Call StopAsync before disposing (#6189) (#6866)

This commit is contained in:
John Luo 2019-01-18 18:30:54 -08:00 committed by GitHub
parent a2151cb89a
commit 8c06f04d50
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 ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue);
} }
await server.StopAsync();
} }
Assert.All(TestSink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information)); 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 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 connection.SendAll(request);
await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue, expectedAllowHeader); await ReceiveBadRequestResponse(connection, expectedResponseStatusCode, server.Context.DateHeaderValue, expectedAllowHeader);
} }
await server.StopAsync();
} }
mockKestrelTrace.Verify(trace => trace.ConnectionBadRequest(It.IsAny<string>(), It.IsAny<BadHttpRequestException>())); 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"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -168,6 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -253,6 +256,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Send(fullRequest); await connection.Send(fullRequest);
await connection.Receive(expectedFullResponse); 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.Send(fullRequest);
await connection.Receive(expectedFullResponse); 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); var badReqEx = await exTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout);
Assert.Equal(RequestRejectionReason.UnexpectedEndOfRequestContent, badReqEx.Reason); 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!"); "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!", "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!"); "Hello World!");
} }
await server.StopAsync();
} }
Assert.Equal(sendString.Length, adapter.BytesRead); Assert.Equal(sendString.Length, adapter.BytesRead);
@ -74,6 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World!"); "Hello World!");
} }
await server.StopAsync();
} }
} }
@ -95,6 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend(); connection.ShutdownSend();
await connection.WaitForConnectionClose(); await connection.WaitForConnectionClose();
} }
await server.StopAsync();
} }
} }
@ -116,6 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend(); connection.ShutdownSend();
await connection.WaitForConnectionClose(); await connection.WaitForConnectionClose();
} }
await server.StopAsync();
} }
} }
@ -162,6 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.WaitForConnectionClose(); 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)}.")); 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!"); "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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -36,12 +36,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await context.Response.WriteAsync("Hello"); await context.Response.WriteAsync("Hello");
await requestTcs.Task; await requestTcs.Task;
}, counter)) }, counter))
using (var connection = server.CreateConnection())
{ {
await connection.SendEmptyGetAsKeepAlive(); ; using (var connection = server.CreateConnection())
await connection.Receive("HTTP/1.1 200 OK"); {
Assert.True(await lockedTcs.Task.DefaultTimeout()); await connection.SendEmptyGetAsKeepAlive(); ;
requestTcs.TrySetResult(null); await connection.Receive("HTTP/1.1 200 OK");
Assert.True(await lockedTcs.Task.DefaultTimeout());
requestTcs.TrySetResult(null);
}
await server.StopAsync();
} }
await releasedTcs.Task.DefaultTimeout(); await releasedTcs.Task.DefaultTimeout();
@ -63,33 +67,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
} }
} }
}, max: 1)) }, max: 1))
using (var disposables = new DisposableStack<InMemoryConnection>())
{ {
var upgraded = server.CreateConnection(); using (var disposables = new DisposableStack<InMemoryConnection>())
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())
{ {
try var upgraded = server.CreateConnection();
{ disposables.Push(upgraded);
// this may throw IOException, depending on how fast Kestrel closes the socket
await rejected.SendEmptyGetAsKeepAlive();
}
catch { }
// connection should close without sending any data await upgraded.SendEmptyGetWithUpgrade();
await rejected.WaitForConnectionClose(); 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 context.Response.WriteAsync("Hello");
await requestTcs.Task; await requestTcs.Task;
}, max)) }, max))
using (var disposables = new DisposableStack<InMemoryConnection>())
{ {
for (var i = 0; i < max; i++) using (var disposables = new DisposableStack<InMemoryConnection>())
{ {
var connection = server.CreateConnection(); for (var i = 0; i < max; i++)
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())
{ {
try var connection = server.CreateConnection();
{ disposables.Push(connection);
// 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.SendEmptyGetAsKeepAlive();
await connection.WaitForConnectionClose(); 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)); await closedTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
Assert.Equal(count, opened); Assert.Equal(count, opened);
Assert.Equal(count, closed); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Concurrent; using System.Collections.Concurrent;
@ -47,6 +47,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
.DefaultTimeout(); .DefaultTimeout();
await connection.Receive("HTTP/1.1 200"); await connection.Receive("HTTP/1.1 200");
} }
await server.StopAsync();
} }
// capture list here as other tests executing in parallel may log events // capture list here as other tests executing in parallel may log events

View File

@ -67,6 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.Http2
await WaitForConnectionErrorAsync(reader, ignoreNonGoAwayFrames: false, expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.INADEQUATE_SECURITY); await WaitForConnectionErrorAsync(reader, ignoreNonGoAwayFrames: false, expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.INADEQUATE_SECURITY);
reader.Complete(); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
public class HttpConnectionManagerTests : LoggedTest 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 #if !DEBUG
[ConditionalFact] [ConditionalFact]
[NoDebuggerCondition] [NoDebuggerCondition]
@ -69,6 +69,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
} }
Assert.True(logWaitAttempts < 10); Assert.True(logWaitAttempts < 10);
await server.StopAsync();
} }
} }
#endif #endif

View File

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

View File

@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
validateCertificate: false); validateCertificate: false);
Assert.Equal("content=Hello+World%3F", result); 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); var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("hello world", result); Assert.Equal("hello world", result);
await server.StopAsync();
} }
} }
@ -104,6 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
await Assert.ThrowsAnyAsync<Exception>( await Assert.ThrowsAnyAsync<Exception>(
() => server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/")); () => 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); var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("hello world", result); 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); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
} }
await server.StopAsync();
} }
} }
@ -207,6 +212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
Assert.Equal(1, selectorCalled); Assert.Equal(1, selectorCalled);
} }
await server.StopAsync();
} }
} }
@ -263,6 +269,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2NoExt)); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2NoExt));
Assert.Equal(2, selectorCalled); Assert.Equal(2, selectorCalled);
} }
await server.StopAsync();
} }
} }
@ -296,6 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false));
Assert.Equal(1, selectorCalled); Assert.Equal(1, selectorCalled);
} }
await server.StopAsync();
} }
} }
@ -339,6 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2));
Assert.Equal(1, selectorCalled); Assert.Equal(1, selectorCalled);
} }
await server.StopAsync();
} }
} }
@ -372,6 +381,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false));
Assert.Equal(1, selectorCalled); Assert.Equal(1, selectorCalled);
} }
await server.StopAsync();
} }
} }
@ -412,6 +422,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, true); await AssertConnectionResult(stream, true);
} }
await server.StopAsync();
} }
} }
@ -430,6 +441,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
Assert.Equal("https", result); Assert.Equal("https", result);
await server.StopAsync();
} }
} }
@ -460,6 +472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var ex = await Assert.ThrowsAsync<IOException>( var ex = await Assert.ThrowsAsync<IOException>(
async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false));
} }
await server.StopAsync();
} }
} }
@ -497,6 +510,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await AssertConnectionResult(stream, true); await AssertConnectionResult(stream, true);
Assert.True(clientCertificateValidationCalled); Assert.True(clientCertificateValidationCalled);
} }
await server.StopAsync();
} }
} }
@ -526,6 +540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, false); await AssertConnectionResult(stream, false);
} }
await server.StopAsync();
} }
} }
@ -554,6 +569,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, false); await AssertConnectionResult(stream, false);
} }
await server.StopAsync();
} }
} }
@ -594,6 +610,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false);
await AssertConnectionResult(stream, true); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -133,6 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
} }
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
await server.StopAsync();
} }
Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id);
@ -161,6 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
} }
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
await server.StopAsync();
} }
Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id); Assert.Equal(1, loggerProvider.FilterLogger.LastEventId.Id);
@ -210,6 +212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await sslStream.ReadAsync(new byte[32], 0, 32); await sslStream.ReadAsync(new byte[32], 0, 32);
} }
await server.StopAsync();
} }
Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged); Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged);
@ -279,6 +282,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12, enabledSslProtocols: SslProtocols.Tls11 | SslProtocols.Tls12,
checkCertificateRevocation: false); checkCertificateRevocation: false);
} }
await server.StopAsync();
} }
Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged); Assert.False(loggerProvider.ErrorLogger.ObjectDisposedExceptionLogged);
@ -286,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197 // Regression test for https://github.com/aspnet/KestrelHttpServer/pull/1197
[Fact] [Fact]
public void ConnectionFilterDoesNotLeakBlock() public async Task ConnectionFilterDoesNotLeakBlock()
{ {
var loggerProvider = new HandshakeErrorLoggerProvider(); var loggerProvider = new HandshakeErrorLoggerProvider();
LoggerFactory.AddProvider(loggerProvider); LoggerFactory.AddProvider(loggerProvider);
@ -302,6 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
connection.Reset(); connection.Reset();
} }
await server.StopAsync();
} }
} }
@ -342,6 +347,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(0, await connection.Stream.ReadAsync(new byte[1], 0, 1).DefaultTimeout()); Assert.Equal(0, await connection.Stream.ReadAsync(new byte[1], 0, 1).DefaultTimeout());
} }
await server.StopAsync();
} }
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout();
@ -371,6 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
enabledSslProtocols: SslProtocols.Tls, enabledSslProtocols: SslProtocols.Tls,
checkCertificateRevocation: false)); checkCertificateRevocation: false));
} }
await server.StopAsync();
} }
await loggerProvider.FilterLogger.LogTcs.Task.DefaultTimeout(); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -30,20 +30,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"GET / HTTP/1.1", {
"Host:", await connection.Send(
"", "GET / HTTP/1.1",
""); "Host:",
await ReceiveResponse(connection, testContext); "",
"");
await ReceiveResponse(connection, testContext);
// Min amount of time between requests that triggers a keep-alive timeout. // Min amount of time between requests that triggers a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1); testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); 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); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) 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( for (var i = 0; i < 10; i++)
"GET / HTTP/1.1", {
"Host:", await connection.Send(
"", "GET / HTTP/1.1",
""); "Host:",
await ReceiveResponse(connection, testContext); "",
"");
await ReceiveResponse(connection, testContext);
// Max amount of time between requests that doesn't trigger a keep-alive timeout. // Max amount of time between requests that doesn't trigger a keep-alive timeout.
testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval; testContext.MockSystemClock.UtcNow += _keepAliveTimeout + Heartbeat.Interval;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); 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); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"POST /consume HTTP/1.1",
"Host:",
"Transfer-Encoding: chunked",
"",
"");
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
{ {
await connection.Send( await connection.Send(
"1", "POST /consume HTTP/1.1",
"a", "Host:",
""); "Transfer-Encoding: chunked",
"",
"");
testContext.MockSystemClock.UtcNow += _shortDelay; await _firstRequestReceived.Task.DefaultTimeout();
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
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 server.StopAsync();
await connection.Send(
"0",
"",
"");
await ReceiveResponse(connection, testContext);
} }
} }
@ -117,32 +126,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
using (var server = CreateServer(testContext, longRunningCt: cts.Token)) using (var server = CreateServer(testContext, longRunningCt: cts.Token))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"GET /longrunning HTTP/1.1",
"Host:",
"",
"");
await _firstRequestReceived.Task.DefaultTimeout();
for (var totalDelay = TimeSpan.Zero; totalDelay < _longDelay; totalDelay += _shortDelay)
{ {
testContext.MockSystemClock.UtcNow += _shortDelay; await connection.Send(
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); "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);
} }
await server.StopAsync();
cts.Cancel();
await ReceiveResponse(connection, testContext);
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await ReceiveResponse(connection, testContext);
} }
} }
@ -153,13 +165,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{ {
// Min amount of time between requests that triggers a keep-alive timeout. using (var connection = server.CreateConnection())
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();
} }
} }
@ -171,30 +186,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
using (var server = CreateServer(testContext, upgradeCt: cts.Token)) using (var server = CreateServer(testContext, upgradeCt: cts.Token))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"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; await connection.Send(
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); "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");
} }
await server.StopAsync();
cts.Cancel();
await connection.Receive("hello, world");
} }
} }
@ -263,4 +281,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
return tcs.Task; 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
@ -29,11 +29,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
listenOptions.UseConnectionLogging(); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -48,6 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(requestRejectedEx); Assert.NotNull(requestRejectedEx);
@ -94,6 +95,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(requestRejectedEx); Assert.NotNull(requestRejectedEx);
@ -137,6 +139,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"A"); "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); Assert.NotNull(invalidOpEx);
@ -248,6 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
""); "");
await connection.ReceiveEnd(); await connection.ReceiveEnd();
} }
await server.StopAsync();
} }
Assert.NotNull(invalidOpEx); Assert.NotNull(invalidOpEx);
@ -287,6 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(requestRejectedEx1); Assert.NotNull(requestRejectedEx1);
@ -334,6 +341,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(requestRejectedEx); 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); Assert.NotNull(requestRejectedEx);
@ -486,6 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(requestRejectedEx1); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; 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); 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"); "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); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"GET / HTTP/1.1", {
headers); await connection.Send(
"GET / HTTP/1.1",
headers);
// Min amount of time between requests that triggers a request headers timeout. // Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1); testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); 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); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) using (var server = CreateServer(testContext))
using (var connection = server.CreateConnection())
{ {
await connection.Send( using (var connection = server.CreateConnection())
"POST / HTTP/1.1", {
"Host:", await connection.Send(
"Content-Length: 1", "POST / HTTP/1.1",
"", "Host:",
""); "Content-Length: 1",
"",
"");
// Min amount of time between requests that triggers a request headers timeout. // Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1); testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
await connection.Send( await connection.Send(
"a"); "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); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager);
using (var server = CreateServer(testContext)) 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. // Min amount of time between requests that triggers a request headers timeout.
testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1); testContext.MockSystemClock.UtcNow += RequestHeadersTimeout + Heartbeat.Interval + TimeSpan.FromTicks(1);
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); 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; testContext.ServerOptions.Limits.MinResponseDataRate = null;
using (var server = CreateServer(testContext)) 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; testContext.MockSystemClock.UtcNow += ShortDelay;
heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow); heartbeatManager.OnHeartbeat(testContext.SystemClock.UtcNow);
}
await ReceiveTimeoutResponse(connection, testContext);
await connection.WaitForConnectionClose();
} }
await server.StopAsync();
await ReceiveTimeoutResponse(connection, testContext);
await connection.WaitForConnectionClose();
} }
} }
@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
@ -42,6 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -87,6 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -126,6 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -53,6 +53,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.False(requestBodyPersisted); Assert.False(requestBodyPersisted);
Assert.False(responseBodyPersisted); Assert.False(responseBodyPersisted);
await server.StopAsync();
} }
} }
@ -121,6 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Read cancelled"); "Read cancelled");
} }
await server.StopAsync();
} }
} }
@ -155,6 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.True(dataRead); Assert.True(dataRead);
@ -226,6 +230,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(queryValue, queryTcs.Task.Result["q"]); Assert.Equal(queryValue, queryTcs.Task.Result["q"]);
} }
} }
await server.StopAsync();
} }
} }
@ -241,6 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
var requestId = await server.HttpClientSlim.GetStringAsync($"http://localhost:{server.Port}/"); var requestId = await server.HttpClientSlim.GetStringAsync($"http://localhost:{server.Port}/");
Assert.Equal(knownId, requestId); Assert.Equal(knownId, requestId);
await server.StopAsync();
} }
} }
@ -297,6 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
usedIds.Add(id); usedIds.Add(id);
} }
} }
await server.StopAsync();
} }
} }
@ -331,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -371,6 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -405,6 +414,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -444,6 +454,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -500,6 +511,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -532,6 +544,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -581,6 +594,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -610,6 +624,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
connection.ShutdownSend(); connection.ShutdownSend();
await connection.ReceiveEnd(); await connection.ReceiveEnd();
} }
await server.StopAsync();
} }
} }
@ -660,6 +675,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -697,6 +713,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
message); message);
} }
await server.StopAsync();
} }
} }
@ -773,6 +790,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.Equal(1, streamCount); Assert.Equal(1, streamCount);
Assert.Equal(1, requestHeadersCount); Assert.Equal(1, requestHeadersCount);
Assert.Equal(1, responseHeadersCount); Assert.Equal(1, responseHeadersCount);
await server.StopAsync();
} }
} }
@ -791,6 +809,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("HTTP/1.1 200 OK"); await connection.Receive("HTTP/1.1 200 OK");
} }
await server.StopAsync();
} }
} }
@ -832,6 +851,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -880,6 +900,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -906,6 +927,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -938,6 +960,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"goodbye"); "goodbye");
} }
await server.StopAsync();
} }
} }
@ -998,6 +1021,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello"); "hello");
} }
await server.StopAsync();
} }
} }
@ -1073,6 +1097,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello2"); "Hello2");
} }
await server.StopAsync();
} }
} }
@ -1117,6 +1142,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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; 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); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -62,6 +62,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await onCompletedTcs.Task.DefaultTimeout(); await onCompletedTcs.Task.DefaultTimeout();
Assert.False(onStartingCalled); Assert.False(onStartingCalled);
} }
await server.StopAsync();
} }
} }
@ -97,6 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
Assert.NotNull(ex); Assert.NotNull(ex);
} }
await server.StopAsync();
} }
} }
@ -164,6 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await Assert.ThrowsAsync<OperationCanceledException>(() => appTcs.Task).DefaultTimeout(); await Assert.ThrowsAsync<OperationCanceledException>(() => appTcs.Task).DefaultTimeout();
} }
await server.StopAsync();
} }
} }
@ -289,6 +292,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -326,6 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
} }
delayTcs.SetResult(null); delayTcs.SetResult(null);
await server.StopAsync();
} }
} }
@ -359,6 +364,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
await onCompletedTcs.Task.DefaultTimeout(); await onCompletedTcs.Task.DefaultTimeout();
@ -391,6 +397,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(readException); Assert.NotNull(readException);
@ -428,6 +435,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -456,6 +464,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -480,6 +489,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -518,6 +528,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// might be 1 by the time ProduceEnd() gets called and the message is logged. // might be 1 by the time ProduceEnd() gets called and the message is logged.
await logTcs.Task.DefaultTimeout(); await logTcs.Task.DefaultTimeout();
} }
await server.StopAsync();
} }
mockKestrelTrace.Verify(kestrelTrace => mockKestrelTrace.Verify(kestrelTrace =>
@ -556,6 +567,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.WaitForConnectionClose(); await connection.WaitForConnectionClose();
} }
await server.StopAsync();
} }
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -592,6 +604,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello,"); "hello,");
} }
await server.StopAsync();
} }
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -631,6 +644,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -666,6 +680,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error); var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
@ -717,6 +732,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// The server should close the connection in this situation. // The server should close the connection in this situation.
await connection.WaitForConnectionClose(); await connection.WaitForConnectionClose();
} }
await server.StopAsync();
} }
mockTrace.Verify(trace => mockTrace.Verify(trace =>
@ -769,6 +785,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// abort triggered by the connection RST and the abort called when // abort triggered by the connection RST and the abort called when
// disposing the server. // disposing the server.
await requestAborted.Task.DefaultTimeout(); await requestAborted.Task.DefaultTimeout();
await server.StopAsync();
} }
// With the server disposed we know all connections were drained and all messages were logged. // With the server disposed we know all connections were drained and all messages were logged.
@ -807,6 +824,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error); var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error);
@ -845,6 +863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -881,6 +900,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -917,6 +937,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -945,6 +966,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -976,6 +998,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
flushed.SetResult(null); flushed.SetResult(null);
} }
await server.StopAsync();
} }
} }
@ -1009,6 +1032,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
flushed.SetResult(null); flushed.SetResult(null);
} }
await server.StopAsync();
} }
} }
@ -1043,6 +1067,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("hello, world"); await connection.Receive("hello, world");
} }
await server.StopAsync();
} }
} }
@ -1084,6 +1109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
expectedResponse); expectedResponse);
} }
await server.StopAsync();
} }
} }
@ -1129,6 +1155,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1175,6 +1202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1218,6 +1246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1261,6 +1290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1307,6 +1337,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1347,6 +1378,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1390,6 +1422,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1427,6 +1460,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1455,6 +1489,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 Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
@ -1525,6 +1560,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.ReceiveEnd(); await connection.ReceiveEnd();
} }
await server.StopAsync();
} }
Assert.True(foundMessage, "Expected log not found"); Assert.True(foundMessage, "Expected log not found");
@ -1568,6 +1604,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 Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
@ -1618,6 +1655,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1642,6 +1680,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -1674,6 +1713,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1718,6 +1758,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1741,6 +1782,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1797,6 +1839,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -1843,6 +1886,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1890,6 +1934,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.False(onStartingCalled); Assert.False(onStartingCalled);
@ -1946,6 +1991,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
// The first registered OnStarting callback should have been called, // The first registered OnStarting callback should have been called,
@ -1996,6 +2042,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
// All OnCompleted callbacks should be called even if they throw. // All OnCompleted callbacks should be called even if they throw.
@ -2039,6 +2086,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
Assert.True(onStartingCalled); Assert.True(onStartingCalled);
@ -2080,6 +2128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello"); "Hello");
} }
await server.StopAsync();
} }
Assert.True(onStartingCalled); Assert.True(onStartingCalled);
@ -2113,6 +2162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error)); Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
@ -2138,6 +2188,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
""); "");
await connection.ReceiveEnd(); await connection.ReceiveEnd();
} }
await server.StopAsync();
} }
} }
@ -2188,6 +2239,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -2236,6 +2288,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Wait for all callbacks to be called. // Wait for all callbacks to be called.
await onStartingTcs.Task.DefaultTimeout(); await onStartingTcs.Task.DefaultTimeout();
} }
await server.StopAsync();
} }
Assert.Equal(1, callOrder.Pop()); Assert.Equal(1, callOrder.Pop());
@ -2287,6 +2340,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
// Wait for all callbacks to be called. // Wait for all callbacks to be called.
await onCompletedTcs.Task.DefaultTimeout(); await onCompletedTcs.Task.DefaultTimeout();
} }
await server.StopAsync();
} }
Assert.Equal(1, callOrder.Pop()); Assert.Equal(1, callOrder.Pop());
@ -2341,6 +2395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello2"); "Hello2");
} }
await server.StopAsync();
} }
} }
@ -2380,6 +2435,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello!"); "Hello!");
} }
await server.StopAsync();
} }
} }
@ -2409,6 +2465,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
} }
@ -2495,6 +2552,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
var disposedStatusCode = await disposedTcs.Task.DefaultTimeout(); var disposedStatusCode = await disposedTcs.Task.DefaultTimeout();
Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode); Assert.Equal(expectedServerStatusCode, (HttpStatusCode)disposedStatusCode);
await server.StopAsync();
} }
if (sendMalformedRequest) 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -90,7 +90,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
}); });
_host = hostBuilder.Build(); _host = hostBuilder.Build();
_host.Start(); _host.Start();
} }
@ -132,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
{ {
try try
{ {
var middlewareTask = _transportFactory.ConnectionDispatcher.OnConnection(transportConnection); var middlewareTask = _transportFactory.ConnectionDispatcher.OnConnection(transportConnection);
var transportTask = CancellationTokenAsTask(transportConnection.ConnectionClosed); var transportTask = CancellationTokenAsTask(transportConnection.ConnectionClosed);
await transportTask; await transportTask;
@ -142,7 +141,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
} }
catch (Exception ex) 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("New protocol data"); await connection.Receive("New protocol data");
await upgrade.Task.DefaultTimeout(); await upgrade.Task.DefaultTimeout();
} }
await server.StopAsync();
} }
} }
@ -104,6 +105,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await upgrade.Task.DefaultTimeout(); await upgrade.Task.DefaultTimeout();
} }
await server.StopAsync();
} }
} }
@ -131,15 +133,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await Task.Delay(100); await Task.Delay(100);
} }
}, new TestServiceContext(LoggerFactory))) }, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{ {
await connection.SendEmptyGetWithUpgrade(); using (var connection = server.CreateConnection())
await connection.Receive("HTTP/1.1 101 Switching Protocols", {
"Connection: Upgrade", await connection.SendEmptyGetWithUpgrade();
$"Date: {server.Context.DateHeaderValue}", await connection.Receive("HTTP/1.1 101 Switching Protocols",
"", "Connection: Upgrade",
""); $"Date: {server.Context.DateHeaderValue}",
await connection.WaitForConnectionClose(); "",
"");
await connection.WaitForConnectionClose();
}
await server.StopAsync();
} }
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task.DefaultTimeout()); 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() public async Task RejectsRequestWithContentLengthAndUpgrade()
{ {
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{ {
await connection.Send("POST / HTTP/1.1", using (var connection = server.CreateConnection())
"Host:", {
"Content-Length: 1", await connection.Send("POST / HTTP/1.1",
"Connection: Upgrade", "Host:",
"", "Content-Length: 1",
""); "Connection: Upgrade",
"",
"");
await connection.ReceiveEnd( await connection.ReceiveEnd(
"HTTP/1.1 400 Bad Request", "HTTP/1.1 400 Bad Request",
"Connection: close", "Connection: close",
$"Date: {server.Context.DateHeaderValue}", $"Date: {server.Context.DateHeaderValue}",
"Content-Length: 0", "Content-Length: 0",
"", "",
""); "");
}
await server.StopAsync();
} }
} }
@ -190,6 +198,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.SendEmptyGetWithUpgrade(); await connection.SendEmptyGetWithUpgrade();
await connection.Receive("HTTP/1.1 200 OK"); 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() public async Task RejectsRequestWithChunkedEncodingAndUpgrade()
{ {
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory))) using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
using (var connection = server.CreateConnection())
{ {
await connection.Send("POST / HTTP/1.1", using (var connection = server.CreateConnection())
"Host:", {
"Transfer-Encoding: chunked", await connection.Send("POST / HTTP/1.1",
"Connection: Upgrade", "Host:",
"", "Transfer-Encoding: chunked",
""); "Connection: Upgrade",
await connection.ReceiveEnd( "",
"HTTP/1.1 400 Bad Request", "");
"Connection: close", await connection.ReceiveEnd(
$"Date: {server.Context.DateHeaderValue}", "HTTP/1.1 400 Bad Request",
"Content-Length: 0", "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.SendEmptyGet();
await connection.Receive("HTTP/1.1 200 OK"); await connection.Receive("HTTP/1.1 200 OK");
} }
await server.StopAsync();
} }
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task).DefaultTimeout(); 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 connection.Receive("HTTP/1.1 200");
} }
} }
await server.StopAsync();
} }
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await upgradeTcs.Task.TimeoutAfter(TimeSpan.FromSeconds(60))); 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 appCompletedTcs.Task.DefaultTimeout();
await server.StopAsync();
} }
} }
} }