Skip to content

Commit

Permalink
Server and client are synchronized via TaskCompletionSource (dotnet#3…
Browse files Browse the repository at this point in the history
…5569)

Http2_PendingSend_SendsReset test fails because client sends the second request with EndOfStream flag sooner than the server reads the last RstStream frame of the first request. This is caused by too short delay before the second request is made on the client. This PR replaces Task.Delay with a synchronization via TaskCompletionSource.

Fixes dotnet#2131
  • Loading branch information
alnikola committed Apr 28, 2020
1 parent ce52022 commit 63ae78b
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,7 @@ public async Task Http2_PendingSend_Cancellation()
public async Task Http2_PendingSend_SendsReset(bool waitForData)
{
var cts = new CancellationTokenSource();
var rstReceived = new TaskCompletionSource<bool>();

string content = new string('*', 300);
var stream = new CustomContent.SlowTestStream(Encoding.UTF8.GetBytes(content), null, count: 60);
Expand All @@ -1649,8 +1650,8 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async url =>
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await client.SendAsync(request, cts.Token));
// Delay for a bit to ensure that the RST_STREAM for the previous request is sent before the next request starts.
await Task.Delay(2000);
// Wait until the RST_STREAM for the previous request is received before the next request starts.
await rstReceived.Task.TimeoutAfter(TimeSpan.FromSeconds(60));
// Send another request to verify that connection is still functional.
request = new HttpRequestMessage(HttpMethod.Get, url);
Expand Down Expand Up @@ -1678,7 +1679,9 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async url =>
frameCount++;
} while (frame.Type != FrameType.RstStream);
Assert.Equal(1, frame.StreamId);
Assert.Equal(1, frame.StreamId);
rstReceived.SetResult(true);
frame = null;
(streamId, requestData) = await connection.ReadAndParseRequestHeaderAsync();
Expand Down

0 comments on commit 63ae78b

Please sign in to comment.