Skip to content

Commit 38f9b9a

Browse files
[SignalR] Fix new flaky test (dotnet#23326)
1 parent a90f442 commit 38f9b9a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,10 +2318,10 @@ public async Task LongPollingConnectionClosingTriggersConnectionClosedToken()
23182318
Assert.Equal("text/plain", deleteContext.Response.ContentType);
23192319
Assert.Equal(HttpConnectionStatus.Disposed, connection.Status);
23202320

2321+
await connection.ConnectionClosed.WaitForCancellationAsync().OrTimeout();
2322+
23212323
// Verify the connection not removed because application is hanging
23222324
Assert.True(manager.TryGetConnection(connection.ConnectionId, out _));
2323-
2324-
Assert.True(connection.ConnectionClosed.IsCancellationRequested);
23252325
}
23262326
}
23272327

@@ -2348,9 +2348,7 @@ public async Task SSEConnectionClosingTriggersConnectionClosedToken()
23482348
// Close the SSE connection
23492349
connection.Transport.Output.Complete();
23502350

2351-
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
2352-
connection.ConnectionClosed.Register(() => tcs.SetResult(null));
2353-
await tcs.Task.OrTimeout();
2351+
await connection.ConnectionClosed.WaitForCancellationAsync().OrTimeout();
23542352
}
23552353
}
23562354

@@ -2381,9 +2379,7 @@ public async Task WebSocketConnectionClosingTriggersConnectionClosedToken()
23812379
await websocket.Accepted.OrTimeout();
23822380
await websocket.Client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", cancellationToken: default).OrTimeout();
23832381

2384-
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
2385-
connection.ConnectionClosed.Register(() => tcs.SetResult(null));
2386-
await tcs.Task.OrTimeout();
2382+
await connection.ConnectionClosed.WaitForCancellationAsync().OrTimeout();
23872383
}
23882384
}
23892385

0 commit comments

Comments
 (0)