Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakey HTTP/2 tests #39588

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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