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);
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);
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();