Skip to content

Fix 48934 test quarantine. #48936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,13 @@ public async Task WebSocket_Abort_Interrupts_Pending_ReceiveAsync()
{
WebSocket serverSocket = null;

// Events that we want to sequence execution across client and server.
var socketWasAccepted = new ManualResetEventSlim();
var socketWasAborted = new ManualResetEventSlim();
var firstReceiveOccured = new ManualResetEventSlim();
var secondReceiveInitiated = new ManualResetEventSlim();

Exception receiveException = null;

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

var serverBuffer = new byte[1024];

var finishedWithConnectionAborted = false;

try
{
while (serverSocket.State is WebSocketState.Open or WebSocketState.CloseSent)
{
var response = await serverSocket.ReceiveAsync(serverBuffer, default);
firstReceiveOccured.Set();
if (firstReceiveOccured.IsSet)
{
var pendingResponse = serverSocket.ReceiveAsync(serverBuffer, default);
secondReceiveInitiated.Set();
var response = await pendingResponse;
}
else
{
var response = await serverSocket.ReceiveAsync(serverBuffer, default);
firstReceiveOccured.Set();
}
}
}
catch (ConnectionAbortedException)
catch (ConnectionAbortedException ex)
{
socketWasAborted.Set();
finishedWithConnectionAborted = true;
receiveException = ex;
}
catch (Exception ex)
{
// Capture this exception so a test failure can give us more information.
receiveException = ex;
}
finally
{
Assert.True(finishedWithConnectionAborted);
Assert.IsType<ConnectionAbortedException>(receiveException);
}
}))
{
Expand All @@ -550,6 +566,9 @@ public async Task WebSocket_Abort_Interrupts_Pending_ReceiveAsync()
var firstReceiveOccuredDidNotTimeout = firstReceiveOccured.Wait(10000);
Assert.True(firstReceiveOccuredDidNotTimeout, "First receive did not occur within the allotted time.");

var secondReceiveInitiatedDidNotTimeout = secondReceiveInitiated.Wait(10000);
Assert.True(secondReceiveInitiatedDidNotTimeout, "Second receive was not initiated within the allotted time.");

serverSocket.Abort();

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