diff --git a/tests/OpenAC.MosswartMassacre.Tests/Backend/TestSocketServer.cs b/tests/OpenAC.MosswartMassacre.Tests/Backend/TestSocketServer.cs index 6ac58d6..7ee2790 100644 --- a/tests/OpenAC.MosswartMassacre.Tests/Backend/TestSocketServer.cs +++ b/tests/OpenAC.MosswartMassacre.Tests/Backend/TestSocketServer.cs @@ -17,6 +17,7 @@ internal sealed class TestSocketServer : IDisposable private readonly CancellationTokenSource _cts = new(); private readonly Task _accept; private WebSocket? _current; + private HttpListenerContext? _currentContext; public TestSocketServer() { @@ -53,7 +54,12 @@ internal sealed class TestSocketServer : IDisposable { WebSocket socket = await WaitForSocketAsync(); socket.Abort(); + // Aborting the socket alone leaves the TCP connection open on some + // platforms' listeners, so the client never sees the drop; ending the + // response closes the connection everywhere, as a real server's drop does. + _currentContext?.Response.Abort(); _current = null; + _currentContext = null; } public string NextFrame(int timeoutMs = 5000) @@ -111,6 +117,7 @@ internal sealed class TestSocketServer : IDisposable Secrets.Enqueue(context.Request.Headers["X-Plugin-Secret"]); HttpListenerWebSocketContext ws = await context.AcceptWebSocketAsync(null); _current = ws.WebSocket; + _currentContext = context; _ = Task.Run(() => ReadLoopAsync(ws.WebSocket)); } }