diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 1e3ae7b852bc..ecbe3071bf35 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -5219,7 +5219,7 @@ await WaitForConnectionErrorAsync( [Fact] public async Task StartConnection_SendPreface_ReturnSettings() { - await InitializeConnectionWithoutPrefaceAsync(_noopApplication); + InitializeConnectionWithoutPreface(_noopApplication); await SendAsync(Http2Connection.ClientPreface); @@ -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")); @@ -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")); @@ -5267,7 +5267,7 @@ public async Task StartTlsConnection_SendHttp1xRequest_NoError() tlsHandshakeMock.SetupGet(m => m.Protocol).Returns(SslProtocols.Tls12); _connection.ConnectionFeatures.Set(tlsHandshakeMock.Object); - await InitializeConnectionWithoutPrefaceAsync(_noopApplication); + InitializeConnectionWithoutPreface(_noopApplication); await SendAsync(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\n")); @@ -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); } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index dd7d062f5810..5c223b11c107 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -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) { @@ -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();