Make WebSocket admission and shutdown tests observe asynchronous closure

This commit is contained in:
ahmed committed 2026-09-19 15:02:37 +03:00
1 parent 3a26224199
commit 1a6ba7a3a4
1 file changed
+11
+11
View File
@@ -334,8 +334,16 @@ public sealed class AspNetCoreIntegrationTests
{ {
// The HTTP upgrade can complete before the EP admission decision closes the // The HTTP upgrade can complete before the EP admission decision closes the
// second transport. What matters is that it is never added to the server. // second transport. What matters is that it is never added to the server.
try
{
if (await rejectedSocket.Connect(host.WebSocketAddress, cancellation.Token)) if (await rejectedSocket.Connect(host.WebSocketAddress, cancellation.Token))
rejectedSocket.Begin(); rejectedSocket.Begin();
}
catch (AsyncException exception) when (exception.InnerException is WebSocketException)
{
// A fast admission rejection can abort the HTTP upgrade itself.
// It must still close this socket and preserve the first peer.
}
await WaitUntilAsync( await WaitUntilAsync(
() => rejectedSocket.State == SocketState.Closed, () => rejectedSocket.State == SocketState.Closed,
@@ -403,6 +411,9 @@ public sealed class AspNetCoreIntegrationTests
await host.Application.StopAsync(cancellation.Token); await host.Application.StopAsync(cancellation.Token);
// Host shutdown closes the server transport; the remote receive loop
// observes that close asynchronously on its own scheduler.
await socket.Completion.WaitAsync(cancellation.Token);
Assert.True(socket.Completion.IsCompleted); Assert.True(socket.Completion.IsCompleted);
Assert.Equal(SocketState.Closed, socket.State); Assert.Equal(SocketState.Closed, socket.State);
Assert.Empty(host.Server.Connections); Assert.Empty(host.Server.Connections);