Skip to content

Commit 4cc97d1

Browse files
committed
Fix flaky Http2WebSocket Kestrel test
1 parent 753676f commit 4cc97d1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2WebSocketTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,18 @@ await InitializeConnectionAsync(async context =>
516516
[Fact]
517517
public async Task ExtendedCONNECTMethod_CanHaveNon200ResponseWithBody()
518518
{
519+
var finishedSendingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
520+
519521
await InitializeConnectionAsync(async context =>
520522
{
521523
var connectFeature = context.Features.Get<IHttpExtendedConnectFeature>();
522524
Assert.True(connectFeature.IsExtendedConnect);
523525

526+
// The EndStreamReceived flag might not have been sent let alone received by the server by the time application code completes
527+
// which would result in a RST_STREAM being sent to the client. We wait for the data frame to finish sending
528+
// before allowing application code to complete (relies on inline Pipe completions which we use for tests)
529+
await finishedSendingTcs.Task;
530+
524531
context.Response.StatusCode = Http.StatusCodes.Status418ImATeapot;
525532
context.Response.ContentLength = 2;
526533
await context.Response.Body.WriteAsync(new byte[1] { 0x01 });
@@ -543,6 +550,8 @@ await InitializeConnectionAsync(async context =>
543550

544551
await SendDataAsync(1, new byte[10241], endStream: true);
545552

553+
finishedSendingTcs.SetResult();
554+
546555
var headersFrame = await ExpectAsync(Http2FrameType.HEADERS,
547556
withLength: 40,
548557
withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS,

0 commit comments

Comments
 (0)