Skip to content

Commit

Permalink
Fix flakey HTTP/2 tests (#39588)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Jan 19, 2022
1 parent 1ca0709 commit 7f67c1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5219,7 +5219,7 @@ await WaitForConnectionErrorAsync<Http2ConnectionErrorException>(
[Fact]
public async Task StartConnection_SendPreface_ReturnSettings()
{
await InitializeConnectionWithoutPrefaceAsync(_noopApplication);
InitializeConnectionWithoutPreface(_noopApplication);

await SendAsync(Http2Connection.ClientPreface);

Expand All @@ -5234,7 +5234,7 @@ await ExpectAsync(Http2FrameType.SETTINGS,
[Fact]
public async Task StartConnection_SendHttp1xRequest_ReturnHttp11Status400()
{
await InitializeConnectionWithoutPrefaceAsync(_noopApplication);
InitializeConnectionWithoutPreface(_noopApplication);

await SendAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n"));

Expand All @@ -5247,7 +5247,7 @@ public async Task StartConnection_SendHttp1xRequest_ReturnHttp11Status400()
[Fact]
public async Task StartConnection_SendHttp1xRequest_ExceedsRequestLineLimit_ProtocolError()
{
await InitializeConnectionWithoutPrefaceAsync(_noopApplication);
InitializeConnectionWithoutPreface(_noopApplication);

await SendAsync(Encoding.ASCII.GetBytes($"GET /{new string('a', _connection.Limits.MaxRequestLineSize)} HTTP/1.1\r\n"));

Expand All @@ -5267,7 +5267,7 @@ public async Task StartTlsConnection_SendHttp1xRequest_NoError()
tlsHandshakeMock.SetupGet(m => m.Protocol).Returns(SslProtocols.Tls12);
_connection.ConnectionFeatures.Set<ITlsHandshakeFeature>(tlsHandshakeMock.Object);

await InitializeConnectionWithoutPrefaceAsync(_noopApplication);
InitializeConnectionWithoutPreface(_noopApplication);

await SendAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n"));

Expand All @@ -5277,7 +5277,7 @@ public async Task StartTlsConnection_SendHttp1xRequest_NoError()
[Fact]
public async Task StartConnection_SendNothing_NoError()
{
await InitializeConnectionWithoutPrefaceAsync(_noopApplication);
InitializeConnectionWithoutPreface(_noopApplication);

await StopConnectionAsync(expectedLastStreamId: 0, ignoreNonGoAwayFrames: false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ protected void CreateConnection()
_timeoutControl.Initialize(_serviceContext.SystemClock.UtcNow.Ticks);
}

protected async Task InitializeConnectionWithoutPrefaceAsync(RequestDelegate application)
protected void InitializeConnectionWithoutPreface(RequestDelegate application)
{
if (_connection == null)
{
Expand All @@ -493,14 +493,15 @@ async Task CompletePipeOnTaskCompletion()
}

_connectionTask = CompletePipeOnTaskCompletion();

// Lose xUnit's AsyncTestSyncContext so middleware always runs inline for better determinism.
await ThreadPoolAwaitable.Instance;
}

protected async Task InitializeConnectionAsync(RequestDelegate application, int expectedSettingsCount = 3, bool expectedWindowUpdate = true)
{
await InitializeConnectionWithoutPrefaceAsync(application);
InitializeConnectionWithoutPreface(application);

// Lose xUnit's AsyncTestSyncContext so middleware always runs inline for better determinism.
await ThreadPoolAwaitable.Instance;

await SendPreambleAsync();
await SendSettingsAsync();

Expand Down

0 comments on commit 7f67c1f

Please sign in to comment.