@@ -382,18 +382,30 @@ public async Task CreateAsyncCancellationStopsStartedConnectAttemptAsync()
382382 connectGate : gate ,
383383 ct : cancellation . Token ) ;
384384
385- await gate . Started . ConfigureAwait ( false ) ;
385+ Task startedTask = await Task . WhenAny (
386+ gate . Started ,
387+ Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) )
388+ . ConfigureAwait ( false ) ;
389+ Assert . That ( startedTask , Is . SameAs ( gate . Started ) ) ;
390+
386391 cancellation . Cancel ( ) ;
387392
393+ Task completedTask = await Task . WhenAny (
394+ creation ,
395+ Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) )
396+ . ConfigureAwait ( false ) ;
397+ Assert . That ( completedTask , Is . SameAs ( creation ) ) ;
398+
388399 OperationCanceledException exception =
389400 Assert . CatchAsync < OperationCanceledException > ( async ( ) =>
390401 await creation . ConfigureAwait ( false ) ) ! ;
391402 Assert . That ( exception . CancellationToken , Is . EqualTo ( cancellation . Token ) ) ;
392403
393- Task completed = await Task . WhenAny (
394- gate . Stopped ,
395- Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) ) . ConfigureAwait ( false ) ;
396- Assert . That ( completed , Is . SameAs ( gate . Stopped ) ) ;
404+ Task stoppedTask = await Task . WhenAny (
405+ gate . Stopped ,
406+ Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) )
407+ . ConfigureAwait ( false ) ;
408+ Assert . That ( stoppedTask , Is . SameAs ( gate . Stopped ) ) ;
397409 }
398410
399411 [ Test ]
@@ -709,7 +721,8 @@ public async ValueTask<IDisposable> AcquireAsync(
709721 m_stopped . TrySetResult ( null ) ;
710722 }
711723
712- return new EmptyLease ( ) ;
724+ throw new InvalidOperationException (
725+ "The blocking connect gate unexpectedly completed without cancellation." ) ;
713726 }
714727
715728 private readonly TaskCompletionSource < object ? > m_started =
@@ -718,13 +731,6 @@ public async ValueTask<IDisposable> AcquireAsync(
718731 new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
719732 }
720733
721- private sealed class EmptyLease : IDisposable
722- {
723- public void Dispose ( )
724- {
725- }
726- }
727-
728734#pragma warning disable IDE0051 , RCS1213 // Test scaffold kept for ManagedSession construction tests.
729735 private static ApplicationConfiguration CreateClientConfiguration (
730736 ITelemetryContext telemetry )
0 commit comments