Skip to content

Commit 0356ba0

Browse files
authored
Fix 48934 test quarantine. (#48936)
1 parent e1f6684 commit 0356ba0

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/Middleware/WebSockets/test/UnitTests/WebSocketMiddlewareTests.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,13 @@ public async Task WebSocket_Abort_Interrupts_Pending_ReceiveAsync()
503503
{
504504
WebSocket serverSocket = null;
505505

506+
// Events that we want to sequence execution across client and server.
506507
var socketWasAccepted = new ManualResetEventSlim();
507508
var socketWasAborted = new ManualResetEventSlim();
508509
var firstReceiveOccured = new ManualResetEventSlim();
510+
var secondReceiveInitiated = new ManualResetEventSlim();
511+
512+
Exception receiveException = null;
509513

510514
await using (var server = KestrelWebSocketHelpers.CreateServer(LoggerFactory, out var port, async context =>
511515
{
@@ -515,24 +519,36 @@ public async Task WebSocket_Abort_Interrupts_Pending_ReceiveAsync()
515519

516520
var serverBuffer = new byte[1024];
517521

518-
var finishedWithConnectionAborted = false;
519-
520522
try
521523
{
522524
while (serverSocket.State is WebSocketState.Open or WebSocketState.CloseSent)
523525
{
524-
var response = await serverSocket.ReceiveAsync(serverBuffer, default);
525-
firstReceiveOccured.Set();
526+
if (firstReceiveOccured.IsSet)
527+
{
528+
var pendingResponse = serverSocket.ReceiveAsync(serverBuffer, default);
529+
secondReceiveInitiated.Set();
530+
var response = await pendingResponse;
531+
}
532+
else
533+
{
534+
var response = await serverSocket.ReceiveAsync(serverBuffer, default);
535+
firstReceiveOccured.Set();
536+
}
526537
}
527538
}
528-
catch (ConnectionAbortedException)
539+
catch (ConnectionAbortedException ex)
529540
{
530541
socketWasAborted.Set();
531-
finishedWithConnectionAborted = true;
542+
receiveException = ex;
543+
}
544+
catch (Exception ex)
545+
{
546+
// Capture this exception so a test failure can give us more information.
547+
receiveException = ex;
532548
}
533549
finally
534550
{
535-
Assert.True(finishedWithConnectionAborted);
551+
Assert.IsType<ConnectionAbortedException>(receiveException);
536552
}
537553
}))
538554
{
@@ -550,6 +566,9 @@ public async Task WebSocket_Abort_Interrupts_Pending_ReceiveAsync()
550566
var firstReceiveOccuredDidNotTimeout = firstReceiveOccured.Wait(10000);
551567
Assert.True(firstReceiveOccuredDidNotTimeout, "First receive did not occur within the allotted time.");
552568

569+
var secondReceiveInitiatedDidNotTimeout = secondReceiveInitiated.Wait(10000);
570+
Assert.True(secondReceiveInitiatedDidNotTimeout, "Second receive was not initiated within the allotted time.");
571+
553572
serverSocket.Abort();
554573

555574
var socketWasAbortedDidNotTimeout = socketWasAborted.Wait(1000); // Give it a second to process the abort.

0 commit comments

Comments
 (0)