Call StopAsync before disposing (#6189)

This commit is contained in:
David Fowler 2018-12-30 01:36:30 -04:00 committed by GitHub
parent b12c33dbc3
commit 010c1f0c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 478 additions and 243 deletions

View File

@ -166,6 +166,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"");
await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue);
}
await server.StopAsync();
}
Assert.All(TestSink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information));
@ -185,6 +187,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await client.Receive("HTTP/1.1 400");
}
await server.StopAsync();
}
}
@ -206,6 +210,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.SendAll(request);
await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue, expectedAllowHeader);
}
await server.StopAsync();
}
mockKestrelTrace.Verify(trace => trace.ConnectionBadRequest(It.IsAny<string>(), It.IsAny<BadHttpRequestException>()));

View File

@ -114,6 +114,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Goodbye");
}
await server.StopAsync();
}
}
@ -168,6 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -253,6 +256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Send(fullRequest);
await connection.Receive(expectedFullResponse);
}
await server.StopAsync();
}
}
@ -297,6 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -338,6 +344,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -424,6 +431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Send(fullRequest);
await connection.Receive(expectedFullResponse);
}
await server.StopAsync();
}
}
@ -467,6 +475,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -511,6 +520,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -615,6 +625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -662,6 +673,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var badReqEx = await exTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout);
Assert.Equal(RequestRejectionReason.UnexpectedEndOfRequestContent, badReqEx.Reason);
}
await server.StopAsync();
}
}
}

View File

@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -75,6 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World!");
}
await server.StopAsync();
}
}
@ -111,6 +113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -147,6 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -183,6 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -227,6 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -257,6 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -290,6 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"Hello World!",
"");
}
await server.StopAsync();
}
}
@ -322,6 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -368,6 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -406,6 +416,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
}

View File

@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World!");
}
await server.StopAsync();
}
Assert.Equal(sendString.Length, adapter.BytesRead);
@ -74,6 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World!");
}
await server.StopAsync();
}
}
@ -95,6 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend();
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
}
@ -116,6 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend();
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
}
@ -162,6 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Message.Contains($"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}."));
@ -197,6 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World!");
}
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -36,12 +36,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await context.Response.WriteAsync("Hello");
await requestTcs.Task;
}, counter))
using (var connection = server.CreateConnection())
{
await connection.SendEmptyGetAsKeepAlive(); ;
await connection.Receive("HTTP/1.1 200 OK");
Assert.True(await lockedTcs.Task.DefaultTimeout());
requestTcs.TrySetResult(null);
using (var connection = server.CreateConnection())
{
await connection.SendEmptyGetAsKeepAlive(); ;
await connection.Receive("HTTP/1.1 200 OK");
Assert.True(await lockedTcs.Task.DefaultTimeout());
requestTcs.TrySetResult(null);
}
await server.StopAsync();
}
await releasedTcs.Task.DefaultTimeout();
@ -63,33 +67,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
}
}, max: 1))
using (var disposables = new DisposableStack<InMemoryConnection>())
{
var upgraded = server.CreateConnection();
disposables.Push(upgraded);
await upgraded.SendEmptyGetWithUpgrade();
await upgraded.Receive("HTTP/1.1 101");
// once upgraded, normal connection limit is decreased to allow room for more "normal" connections
var connection = server.CreateConnection();
disposables.Push(connection);
await connection.SendEmptyGetAsKeepAlive();
await connection.Receive("HTTP/1.1 200 OK");
using (var rejected = server.CreateConnection())
using (var disposables = new DisposableStack<InMemoryConnection>())
{
try
{
// this may throw IOException, depending on how fast Kestrel closes the socket
await rejected.SendEmptyGetAsKeepAlive();
}
catch { }
var upgraded = server.CreateConnection();
disposables.Push(upgraded);
// connection should close without sending any data
await rejected.WaitForConnectionClose();
await upgraded.SendEmptyGetWithUpgrade();
await upgraded.Receive("HTTP/1.1 101");
// once upgraded, normal connection limit is decreased to allow room for more "normal" connections
var connection = server.CreateConnection();
disposables.Push(connection);
await connection.SendEmptyGetAsKeepAlive();
await connection.Receive("HTTP/1.1 200 OK");
using (var rejected = server.CreateConnection())
{
try
{
// this may throw IOException, depending on how fast Kestrel closes the socket
await rejected.SendEmptyGetAsKeepAlive();
}
catch { }
// connection should close without sending any data
await rejected.WaitForConnectionClose();
}
}
await server.StopAsync();
}
}
@ -104,35 +111,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await context.Response.WriteAsync("Hello");
await requestTcs.Task;
}, max))
using (var disposables = new DisposableStack<InMemoryConnection>())
{
for (var i = 0; i < max; i++)
using (var disposables = new DisposableStack<InMemoryConnection>())
{
var connection = server.CreateConnection();
disposables.Push(connection);
await connection.SendEmptyGetAsKeepAlive();
await connection.Receive("HTTP/1.1 200 OK");
}
// limit has been reached
for (var i = 0; i < 10; i++)
{
using (var connection = server.CreateConnection())
for (var i = 0; i < max; i++)
{
try
{
// this may throw IOException, depending on how fast Kestrel closes the socket
await connection.SendEmptyGetAsKeepAlive();
}
catch { }
var connection = server.CreateConnection();
disposables.Push(connection);
// connection should close without sending any data
await connection.WaitForConnectionClose();
await connection.SendEmptyGetAsKeepAlive();
await connection.Receive("HTTP/1.1 200 OK");
}
}
requestTcs.TrySetResult(null);
// limit has been reached
for (var i = 0; i < 10; i++)
{
using (var connection = server.CreateConnection())
{
try
{
// this may throw IOException, depending on how fast Kestrel closes the socket
await connection.SendEmptyGetAsKeepAlive();
}
catch { }
// connection should close without sending any data
await connection.WaitForConnectionClose();
}
}
requestTcs.TrySetResult(null);
}
await server.StopAsync();
}
}
@ -189,6 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await closedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
Assert.Equal(count, opened);
Assert.Equal(count, closed);
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
@ -45,6 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Concurrent;
@ -47,6 +47,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
.DefaultTimeout();
await connection.Receive("HTTP/1.1 200");
}
await server.StopAsync();
}
// capture list here as other tests executing in parallel may log events

View File

@ -65,6 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.Http2
await WaitForConnectionErrorAsync(reader, ignoreNonGoAwayFrames: false, expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.INADEQUATE_SECURITY);
reader.Complete();
}
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
public class HttpConnectionManagerTests : LoggedTest
{
// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
#if !DEBUG
[ConditionalFact]
[NoDebuggerCondition]
@ -69,6 +69,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
Assert.True(logWaitAttempts < 10);
await server.StopAsync();
}
}
#endif

View File

@ -70,6 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Send(request);
await connection.Receive(expectedResponse);
}
await server.StopAsync();
}
}
@ -88,6 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error

View File

@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
validateCertificate: false);
Assert.Equal("content=Hello+World%3F", result);
await server.StopAsync();
}
}
@ -81,6 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("hello world", result);
await server.StopAsync();
}
}
@ -104,6 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
await Assert.ThrowsAnyAsync<Exception>(
() => server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/"));
await server.StopAsync();
}
}
@ -132,6 +135,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("hello world", result);
await server.StopAsync();
}
}
@ -165,6 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
}
await server.StopAsync();
}
}
@ -201,6 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
Assert.Equal(1, selectorCalled);
}
await server.StopAsync();
}
}
@ -251,6 +257,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2NoExt));
Assert.Equal(2, selectorCalled);
}
await server.StopAsync();
}
}
@ -284,6 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false));
Assert.Equal(1, selectorCalled);
}
await server.StopAsync();
}
}
@ -321,6 +329,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
Assert.Equal(1, selectorCalled);
}
await server.StopAsync();
}
}
@ -354,6 +363,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false));
Assert.Equal(1, selectorCalled);
}
await server.StopAsync();
}
}
@ -394,6 +404,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, true);
}
await server.StopAsync();
}
}
@ -412,6 +423,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("https", result);
await server.StopAsync();
}
}
@ -442,6 +454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var ex = await Assert.ThrowsAsync<IOException>(
async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false));
}
await server.StopAsync();
}
}
@ -479,6 +492,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await AssertConnectionResult(stream, true);
Assert.True(clientCertificateValidationCalled);
}
await server.StopAsync();
}
}
@ -508,6 +522,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, false);
}
await server.StopAsync();
}
}
@ -536,6 +551,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, false);
}
await server.StopAsync();
}
}
@ -576,6 +592,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, true);
}
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -134,6 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
await server.StopAsync();
}
Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id);
@ -162,6 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
await server.StopAsync();
}
Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id);
@ -211,6 +213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await sslStream.ReadAsync(new byte[32], 0, 32);
}
await server.StopAsync();
}
Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged);
@ -280,6 +283,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12,
checkCertificateRevocation: false);
}
await server.StopAsync();
}
Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged);
@ -287,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197
[Fact]
public void ConnectionFilterDoesNotLeakBlock()
public async Task ConnectionFilterDoesNotLeakBlock()
{
var loggerProvider = new HandshakeErrorLoggerProvider();
LoggerFactory.AddProvider(loggerProvider);
@ -303,6 +307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
connection.Reset();
}
await server.StopAsync();
}
}
@ -343,6 +348,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(0, await connection.Stream.ReadAsync(new byte[1], 0, 1).DefaultTimeout());
}
await server.StopAsync();
}
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
@ -372,6 +378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
enabledSslProtocols: SslProtocols.Tls,
checkCertificateRevocation: false));
}
await server.StopAsync();
}
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -30,20 +30,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
// Min amount of time between requests that triggers a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
// Min amount of time between requests that triggers a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.WaitForConnectionClose();
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
}
@ -54,21 +57,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
for (var i = 0; i < 10; i++)
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
for (var i = 0; i < 10; i++)
{
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
// Max amount of time between requests that doesn't trigger a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
// Max amount of time between requests that doesn't trigger a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
}
await server.StopAsync();
}
}
@ -79,33 +85,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
await connection.Send(
"POST /consume HTTP/1.1",
"Host:",
"Transfer-Encoding: chunked",
"",
"");
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
using (var connection = server.CreateConnection())
{
await connection.Send(
"1",
"a",
"");
"POST /consume HTTP/1.1",
"Host:",
"Transfer-Encoding: chunked",
"",
"");
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
{
await connection.Send(
"1",
"a",
"");
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
await connection.Send(
"0",
"",
"");
await ReceiveResponse(connection, testContext);
}
await connection.Send(
"0",
"",
"");
await ReceiveResponse(connection, testContext);
await server.StopAsync();
}
}
@ -117,32 +126,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var cts = new CancellationTokenSource();
using (var server = CreateServer(testContext, longRunningCt: cts.Token))
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET /longrunning HTTP/1.1",
"Host:",
"",
"");
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
using (var connection = server.CreateConnection())
{
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.Send(
"GET /longrunning HTTP/1.1",
"Host:",
"",
"");
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
{
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
cts.Cancel();
await ReceiveResponse(connection, testContext);
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
}
cts.Cancel();
await ReceiveResponse(connection, testContext);
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
await server.StopAsync();
}
}
@ -153,13 +165,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
// Min amount of time between requests that triggers a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
using (var connection = server.CreateConnection())
{
// Min amount of time between requests that triggers a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.WaitForConnectionClose();
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
}
@ -171,30 +186,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var cts = new CancellationTokenSource();
using (var server = CreateServer(testContext, upgradeCt: cts.Token))
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET /upgrade HTTP/1.1",
"Host:",
"Connection: Upgrade",
"",
"");
await connection.Receive(
"HTTP/1.1 101 Switching Protocols",
"Connection: Upgrade",
$"Date: {testContext.DateHeaderValue}",
"",
"");
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
using (var connection = server.CreateConnection())
{
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.Send(
"GET /upgrade HTTP/1.1",
"Host:",
"Connection: Upgrade",
"",
"");
await connection.Receive(
"HTTP/1.1 101 Switching Protocols",
"Connection: Upgrade",
$"Date: {testContext.DateHeaderValue}",
"",
"");
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
{
testContext.MockSystemClock.UtcNow += _shortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
cts.Cancel();
await connection.Receive("hello, world");
}
cts.Cancel();
await connection.Receive("hello, world");
await server.StopAsync();
}
}
@ -263,4 +281,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
return tcs.Task;
}
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
@ -29,11 +29,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
listenOptions.UseConnectionLogging();
}))
{
var response = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false)
.DefaultTimeout();
{
var response = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false)
.DefaultTimeout();
Assert.Equal("Hello World!", response);
Assert.Equal("Hello World!", response);
}
await server.StopAsync();
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -48,6 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx);
@ -94,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx);
@ -137,6 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"A");
}
await server.StopAsync();
}
}
@ -169,6 +172,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -209,6 +213,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(invalidOpEx);
@ -248,6 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"");
await connection.ReceiveEnd();
}
await server.StopAsync();
}
Assert.NotNull(invalidOpEx);
@ -287,6 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx1);
@ -334,6 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx);
@ -379,6 +387,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -447,6 +456,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx);
@ -486,6 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(requestRejectedEx1);

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
@ -44,6 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -67,6 +68,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -88,6 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -133,6 +134,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 32 && w.LogLevel == LogLevel.Information);
@ -206,6 +208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
}
}

View File

@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -75,6 +76,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -98,6 +100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -122,6 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -156,4 +160,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
});
}
}
}
}

View File

@ -29,17 +29,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
headers);
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
headers);
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await ReceiveTimeoutResponse(connection, testContext);
await ReceiveTimeoutResponse(connection, testContext);
}
await server.StopAsync();
}
}
@ -50,23 +53,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
await connection.Send(
"POST / HTTP/1.1",
"Host:",
"Content-Length: 1",
"",
"");
using (var connection = server.CreateConnection())
{
await connection.Send(
"POST / HTTP/1.1",
"Host:",
"Content-Length: 1",
"",
"");
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.Send(
"a");
await connection.Send(
"a");
await ReceiveResponse(connection, testContext);
await ReceiveResponse(connection, testContext);
}
await server.StopAsync();
}
}
@ -79,15 +85,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
await connection.Send(requestLine);
using (var connection = server.CreateConnection())
{
await connection.Send(requestLine);
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
// Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await ReceiveTimeoutResponse(connection, testContext);
await ReceiveTimeoutResponse(connection, testContext);
}
await server.StopAsync();
}
}
@ -101,19 +110,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
testContext.ServerOptions.Limits.MinResponseDataRate = null;
using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{
foreach (var ch in "POST / HTTP/1.1\r\nHost:\r\n\r\n")
using (var connection = server.CreateConnection())
{
await connection.Send(ch.ToString());
foreach (var ch in "POST / HTTP/1.1\r\nHost:\r\n\r\n")
{
await connection.Send(ch.ToString());
testContext.MockSystemClock.UtcNow += ShortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
testContext.MockSystemClock.UtcNow += ShortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
await ReceiveTimeoutResponse(connection, testContext);
await connection.WaitForConnectionClose();
}
await ReceiveTimeoutResponse(connection, testContext);
await connection.WaitForConnectionClose();
await server.StopAsync();
}
}
@ -156,4 +168,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"");
}
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
@ -42,6 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -87,6 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -126,6 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -53,6 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.False(requestBodyPersisted);
Assert.False(responseBodyPersisted);
await server.StopAsync();
}
}
@ -119,6 +121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Read cancelled");
}
await server.StopAsync();
}
}
@ -153,6 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.True(dataRead);
@ -224,6 +228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(queryValue, queryTcs.Task.Result["q"]);
}
}
await server.StopAsync();
}
}
@ -239,6 +244,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{
var requestId = await server.HttpClientSlim.GetStringAsync($"http://localhost:{server.Port}/");
Assert.Equal(knownId, requestId);
await server.StopAsync();
}
}
@ -295,6 +301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
usedIds.Add(id);
}
}
await server.StopAsync();
}
}
@ -329,6 +336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Goodbye");
}
await server.StopAsync();
}
}
@ -369,6 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -403,6 +412,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Goodbye");
}
await server.StopAsync();
}
}
@ -442,6 +452,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Goodbye");
}
await server.StopAsync();
}
}
@ -498,6 +509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Goodbye");
}
await server.StopAsync();
}
}
@ -530,6 +542,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -579,6 +592,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -608,6 +622,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend();
await connection.ReceiveEnd();
}
await server.StopAsync();
}
}
@ -658,6 +673,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -695,6 +711,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
message);
}
await server.StopAsync();
}
}
@ -771,6 +788,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(1, streamCount);
Assert.Equal(1, requestHeadersCount);
Assert.Equal(1, responseHeadersCount);
await server.StopAsync();
}
}
@ -789,6 +807,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("HTTP/1.1 200 OK");
}
await server.StopAsync();
}
}
@ -830,6 +849,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -878,6 +898,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -904,6 +925,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -936,6 +958,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"goodbye");
}
await server.StopAsync();
}
}
@ -996,6 +1019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello");
}
await server.StopAsync();
}
}
@ -1071,6 +1095,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello2");
}
await server.StopAsync();
}
}
@ -1115,6 +1140,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -79,6 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
Assert.Single(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 28 && w.LogLevel == LogLevel.Information);
}
await server.StopAsync();
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -62,6 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await onCompletedTcs.Task.DefaultTimeout();
Assert.False(onStartingCalled);
}
await server.StopAsync();
}
}
@ -97,6 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.NotNull(ex);
}
await server.StopAsync();
}
}
@ -154,6 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await Assert.ThrowsAsync<OperationCanceledException>(() => appTcs.Task).DefaultTimeout();
}
await server.StopAsync();
}
}
@ -279,6 +282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -316,6 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
delayTcs.SetResult(null);
await server.StopAsync();
}
}
@ -349,6 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
await onCompletedTcs.Task.DefaultTimeout();
@ -381,6 +387,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.NotNull(readException);
@ -418,6 +425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -446,6 +454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -470,6 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -508,6 +518,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// might be 1 by the time ProduceEnd() gets called and the message is logged.
await logTcs.Task.DefaultTimeout();
}
await server.StopAsync();
}
mockKestrelTrace.Verify(kestrelTrace =>
@ -546,6 +557,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -582,6 +594,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello,");
}
await server.StopAsync();
}
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -621,6 +634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -656,6 +670,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -707,6 +722,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// The server should close the connection in this situation.
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
mockTrace.Verify(trace =>
@ -759,6 +775,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// abort triggered by the connection RST and the abort called when
// disposing the server.
await requestAborted.Task.DefaultTimeout();
await server.StopAsync();
}
// With the server disposed we know all connections were drained and all messages were logged.
@ -797,6 +814,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error);
@ -835,6 +853,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -871,6 +890,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -907,6 +927,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -935,6 +956,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -966,6 +988,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
flushed.SetResult(null);
}
await server.StopAsync();
}
}
@ -999,6 +1022,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
flushed.SetResult(null);
}
await server.StopAsync();
}
}
@ -1033,6 +1057,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("hello, world");
}
await server.StopAsync();
}
}
@ -1074,6 +1099,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
expectedResponse);
}
await server.StopAsync();
}
}
@ -1119,6 +1145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
}
@ -1165,6 +1192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
}
@ -1208,6 +1236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
}
@ -1251,6 +1280,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1297,6 +1327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1337,6 +1368,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1380,6 +1412,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1417,6 +1450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1445,6 +1479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
@ -1515,6 +1550,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.ReceiveEnd();
}
await server.StopAsync();
}
Assert.True(foundMessage, "Expected log not found");
@ -1558,6 +1594,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
@ -1608,6 +1645,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1632,6 +1670,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
}
@ -1664,6 +1703,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1708,6 +1748,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1731,6 +1772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1787,6 +1829,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -1833,6 +1876,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"hello, world");
}
await server.StopAsync();
}
}
@ -1880,6 +1924,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
Assert.False(onStartingCalled);
@ -1936,6 +1981,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
// The first registered OnStarting callback should have been called,
@ -1986,6 +2032,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
// All OnCompleted callbacks should be called even if they throw.
@ -2029,6 +2076,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
Assert.True(onStartingCalled);
@ -2070,6 +2118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello");
}
await server.StopAsync();
}
Assert.True(onStartingCalled);
@ -2103,6 +2152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello World");
}
await server.StopAsync();
}
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -2128,6 +2178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"");
await connection.ReceiveEnd();
}
await server.StopAsync();
}
}
@ -2178,6 +2229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -2226,6 +2278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Wait for all callbacks to be called.
await onStartingTcs.Task.DefaultTimeout();
}
await server.StopAsync();
}
Assert.Equal(1, callOrder.Pop());
@ -2277,6 +2330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Wait for all callbacks to be called.
await onCompletedTcs.Task.DefaultTimeout();
}
await server.StopAsync();
}
Assert.Equal(1, callOrder.Pop());
@ -2331,6 +2385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello2");
}
await server.StopAsync();
}
}
@ -2370,6 +2425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"Hello!");
}
await server.StopAsync();
}
}
@ -2399,6 +2455,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"",
"");
}
await server.StopAsync();
}
}
@ -2485,6 +2542,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var disposedStatusCode = await disposedTcs.Task.DefaultTimeout();
Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode);
await server.StopAsync();
}
if (sendMalformedRequest)

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -90,7 +90,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
});
_host = hostBuilder.Build();
_host.Start();
}
@ -132,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
{
try
{
var middlewareTask = _transportFactory.ConnectionDispatcher.OnConnection(transportConnection);
var middlewareTask = _transportFactory.ConnectionDispatcher.OnConnection(transportConnection);
var transportTask = CancellationTokenAsTask(transportConnection.ConnectionClosed);
await transportTask;
@ -142,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
}
catch (Exception ex)
{
Debug.Assert(false, $"Unexpected exception: {ex}.");
Debug.Assert(false, $"Unexpected exception: {ex}.");
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("New protocol data");
await upgrade.Task.DefaultTimeout();
}
await server.StopAsync();
}
}
@ -104,6 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await upgrade.Task.DefaultTimeout();
}
await server.StopAsync();
}
}
@ -131,15 +133,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await Task.Delay(100);
}
}, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{
await connection.SendEmptyGetWithUpgrade();
await connection.Receive("HTTP/1.1 101 Switching Protocols",
"Connection: Upgrade",
$"Date: {server.Context.DateHeaderValue}",
"",
"");
await connection.WaitForConnectionClose();
using (var connection = server.CreateConnection())
{
await connection.SendEmptyGetWithUpgrade();
await connection.Receive("HTTP/1.1 101 Switching Protocols",
"Connection: Upgrade",
$"Date: {server.Context.DateHeaderValue}",
"",
"");
await connection.WaitForConnectionClose();
}
await server.StopAsync();
}
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task.DefaultTimeout());
@ -150,22 +155,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
public async Task RejectsRequestWithContentLengthAndUpgrade()
{
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{
await connection.Send("POST / HTTP/1.1",
"Host:",
"Content-Length: 1",
"Connection: Upgrade",
"",
"");
using (var connection = server.CreateConnection())
{
await connection.Send("POST / HTTP/1.1",
"Host:",
"Content-Length: 1",
"Connection: Upgrade",
"",
"");
await connection.ReceiveEnd(
"HTTP/1.1 400 Bad Request",
"Connection: close",
$"Date: {server.Context.DateHeaderValue}",
"Content-Length: 0",
"",
"");
await connection.ReceiveEnd(
"HTTP/1.1 400 Bad Request",
"Connection: close",
$"Date: {server.Context.DateHeaderValue}",
"Content-Length: 0",
"",
"");
}
await server.StopAsync();
}
}
@ -190,6 +198,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.SendEmptyGetWithUpgrade();
await connection.Receive("HTTP/1.1 200 OK");
}
await server.StopAsync();
}
}
@ -197,21 +206,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
public async Task RejectsRequestWithChunkedEncodingAndUpgrade()
{
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{
await connection.Send("POST / HTTP/1.1",
"Host:",
"Transfer-Encoding: chunked",
"Connection: Upgrade",
"",
"");
await connection.ReceiveEnd(
"HTTP/1.1 400 Bad Request",
"Connection: close",
$"Date: {server.Context.DateHeaderValue}",
"Content-Length: 0",
"",
"");
using (var connection = server.CreateConnection())
{
await connection.Send("POST / HTTP/1.1",
"Host:",
"Transfer-Encoding: chunked",
"Connection: Upgrade",
"",
"");
await connection.ReceiveEnd(
"HTTP/1.1 400 Bad Request",
"Connection: close",
$"Date: {server.Context.DateHeaderValue}",
"Content-Length: 0",
"",
"");
}
await server.StopAsync();
}
}
@ -242,6 +254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.SendEmptyGet();
await connection.Receive("HTTP/1.1 200 OK");
}
await server.StopAsync();
}
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task).DefaultTimeout();
@ -293,6 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("HTTP/1.1 200");
}
}
await server.StopAsync();
}
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60)));
@ -333,6 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
await appCompletedTcs.Task.DefaultTimeout();
await server.StopAsync();
}
}
}