@@ -208,7 +208,7 @@ public void Serialize_EventMessage_IncludesEventData ()
208208 }
209209
210210 [ TestMethod ]
211- public void Serialize_EventMessage_WithModifyingCollection_DoesNotThrow ( )
211+ public async Task Serialize_EventMessage_WithModifyingCollection_DoesNotThrow ( )
212212 {
213213 // Arrange: Create a mutable dictionary that simulates concurrent modification
214214 var payload = new Dictionary < string , object > { { "key1" , "value1" } } ;
@@ -226,6 +226,7 @@ public void Serialize_EventMessage_WithModifyingCollection_DoesNotThrow ()
226226 } ;
227227
228228 // Act: Modify the dictionary in a separate task while serializing
229+ Exception exception = null ;
229230 var serializationTask = Task . Run ( ( ) =>
230231 {
231232 // Serialize multiple times to increase chance of collision
@@ -252,14 +253,18 @@ public void Serialize_EventMessage_WithModifyingCollection_DoesNotThrow ()
252253 // Assert: Both tasks should complete without exception
253254 try
254255 {
255- Task . WaitAll ( [ serializationTask , modificationTask ] , TimeSpan . FromSeconds ( 5 ) ) ;
256- Assert . IsTrue ( serializationTask . IsCompletedSuccessfully ) ;
257- Assert . IsTrue ( modificationTask . IsCompletedSuccessfully ) ;
256+ await Task . WhenAll ( serializationTask , modificationTask ) ;
258257 }
259- catch ( AggregateException ex )
258+ catch ( Exception ex )
260259 {
261- Assert . Fail ( $ "Serialization failed during concurrent modification: { ex . InnerException ? . Message } " ) ;
260+ // Capture for debugging, but don't assert here
261+ exception = ex ;
262262 }
263+
264+ // Assert (outside the catch)
265+ Assert . IsNull ( exception , $ "Serialization failed during concurrent modification: { exception } " ) ;
266+ Assert . IsTrue ( serializationTask . IsCompletedSuccessfully ) ;
267+ Assert . IsTrue ( modificationTask . IsCompletedSuccessfully ) ;
263268 }
264269
265270 [ TestMethod ]
0 commit comments