@@ -279,6 +279,7 @@ public async Task Client_CanResumePostResponseStream_AfterDisconnection()
279279 [ Fact ]
280280 public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection ( )
281281 {
282+ var timeout = TimeSpan . FromSeconds ( 10 ) ;
282283 using var faultingStreamHandler = new FaultingStreamHandler ( )
283284 {
284285 InnerHandler = SocketsHttpHandler ,
@@ -304,12 +305,12 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
304305 await using var client = await ConnectClientAsync ( ) ;
305306
306307 // Get the server instance
307- var server = await serverTcs . Task . WaitAsync ( TestContext . Current . CancellationToken ) ;
308+ var server = await serverTcs . Task . WaitAsync ( timeout , TestContext . Current . CancellationToken ) ;
308309
309310 // Set up notification tracking with unique messages
310- var clientReceivedInitialNotificationTcs = new TaskCompletionSource ( ) ;
311- var clientReceivedReplayedNotificationTcs = new TaskCompletionSource ( ) ;
312- var clientReceivedReconnectNotificationTcs = new TaskCompletionSource ( ) ;
311+ var clientReceivedInitialNotificationTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
312+ var clientReceivedReplayedNotificationTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
313+ var clientReceivedReconnectNotificationTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
313314
314315 const string CustomNotificationMethod = "test/custom_notification" ;
315316 const string InitialMessage = "Initial notification" ;
@@ -343,11 +344,14 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
343344 return default ;
344345 } ) ;
345346
347+ // Wait for the client's unsolicited message stream to be established before sending notifications
348+ await faultingStreamHandler . WaitForUnsolicitedMessageStreamAsync ( TestContext . Current . CancellationToken ) ;
349+
346350 // Send a custom notification to the client on the unsolicited message stream
347351 await server . SendNotificationAsync ( CustomNotificationMethod , new JsonObject { [ "message" ] = InitialMessage } , cancellationToken : TestContext . Current . CancellationToken ) ;
348352
349353 // Wait for client to receive the first notification
350- await clientReceivedInitialNotificationTcs . Task . WaitAsync ( TestContext . Current . CancellationToken ) ;
354+ await clientReceivedInitialNotificationTcs . Task . WaitAsync ( timeout , TestContext . Current . CancellationToken ) ;
351355
352356 // Fault the unsolicited message stream (GET SSE)
353357 var reconnectAttempt = await faultingStreamHandler . TriggerFaultAsync ( TestContext . Current . CancellationToken ) ;
@@ -359,13 +363,13 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
359363 reconnectAttempt . Continue ( ) ;
360364
361365 // Wait for client to receive the notification via replay
362- await clientReceivedReplayedNotificationTcs . Task . WaitAsync ( TestContext . Current . CancellationToken ) ;
366+ await clientReceivedReplayedNotificationTcs . Task . WaitAsync ( timeout , TestContext . Current . CancellationToken ) ;
363367
364368 // Send a final notification while the client has reconnected - this should be handled by the transport
365369 await server . SendNotificationAsync ( CustomNotificationMethod , new JsonObject { [ "message" ] = ReconnectMessage } , cancellationToken : TestContext . Current . CancellationToken ) ;
366370
367371 // Wait for the client to receive the final notification
368- await clientReceivedReconnectNotificationTcs . Task . WaitAsync ( TestContext . Current . CancellationToken ) ;
372+ await clientReceivedReconnectNotificationTcs . Task . WaitAsync ( timeout , TestContext . Current . CancellationToken ) ;
369373
370374 // Assert each notification was received exactly once
371375 Assert . Equal ( 1 , initialNotificationReceivedCount ) ;
@@ -531,7 +535,7 @@ public async Task PostResponse_EndsAndSseEventStreamWriterIsDisposed_WhenWriteEv
531535 timeoutCts . CancelAfter ( TimeSpan . FromSeconds ( 10 ) ) ;
532536
533537 // The call task should throw an OCE due to cancellation
534- await Assert . ThrowsAsync < OperationCanceledException > ( ( ) => callTask ) . WaitAsync ( timeoutCts . Token ) ;
538+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => callTask ) . WaitAsync ( timeoutCts . Token ) ;
535539
536540 // Wait for the writer to be disposed
537541 await blockingStore . DisposedTask . WaitAsync ( timeoutCts . Token ) ;
0 commit comments