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 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

@ -65,6 +65,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();
} }
} }
@ -201,6 +206,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();
} }
} }
@ -251,6 +257,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();
} }
} }
@ -284,6 +291,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();
} }
} }
@ -321,6 +329,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();
} }
} }
@ -354,6 +363,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();
} }
} }
@ -394,6 +404,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();
} }
} }
@ -412,6 +423,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();
} }
} }
@ -442,6 +454,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();
} }
} }
@ -479,6 +492,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();
} }
} }
@ -508,6 +522,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();
} }
} }
@ -536,6 +551,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();
} }
} }
@ -576,6 +592,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;
@ -134,6 +134,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);
@ -162,6 +163,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);
@ -211,6 +213,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);
@ -280,6 +283,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);
@ -287,7 +291,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);
@ -303,6 +307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
connection.Reset(); 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()); 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();
@ -372,6 +378,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();
} }
} }
@ -119,6 +121,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Read cancelled"); "Read cancelled");
} }
await server.StopAsync();
} }
} }
@ -153,6 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.True(dataRead); Assert.True(dataRead);
@ -224,6 +228,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();
} }
} }
@ -239,6 +244,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();
} }
} }
@ -295,6 +301,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
usedIds.Add(id); usedIds.Add(id);
} }
} }
await server.StopAsync();
} }
} }
@ -329,6 +336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -369,6 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
} }
@ -403,6 +412,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -442,6 +452,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -498,6 +509,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Goodbye"); "Goodbye");
} }
await server.StopAsync();
} }
} }
@ -530,6 +542,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "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(); connection.ShutdownSend();
await connection.ReceiveEnd(); 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); message);
} }
await server.StopAsync();
} }
} }
@ -771,6 +788,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();
} }
} }
@ -789,6 +807,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();
} }
} }
@ -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"); "goodbye");
} }
await server.StopAsync();
} }
} }
@ -996,6 +1019,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello"); "hello");
} }
await server.StopAsync();
} }
} }
@ -1071,6 +1095,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello2"); "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. // 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();
} }
} }
@ -154,6 +156,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();
} }
} }
@ -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); delayTcs.SetResult(null);
await server.StopAsync();
} }
} }
@ -349,6 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
await onCompletedTcs.Task.DefaultTimeout(); await onCompletedTcs.Task.DefaultTimeout();
@ -381,6 +387,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.NotNull(readException); 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. // 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 =>
@ -546,6 +557,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);
@ -582,6 +594,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);
@ -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); 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); 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. // The server should close the connection in this situation.
await connection.WaitForConnectionClose(); await connection.WaitForConnectionClose();
} }
await server.StopAsync();
} }
mockTrace.Verify(trace => 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 // 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.
@ -797,6 +814,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);
@ -835,6 +853,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));
@ -871,6 +890,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));
@ -907,6 +927,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));
@ -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); flushed.SetResult(null);
} }
await server.StopAsync();
} }
} }
@ -999,6 +1022,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
flushed.SetResult(null); flushed.SetResult(null);
} }
await server.StopAsync();
} }
} }
@ -1033,6 +1057,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Receive("hello, world"); await connection.Receive("hello, world");
} }
await server.StopAsync();
} }
} }
@ -1074,6 +1099,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
expectedResponse); expectedResponse);
} }
await server.StopAsync();
} }
} }
@ -1119,6 +1145,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1165,6 +1192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1208,6 +1236,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"hello, world"); "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 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 connection.ReceiveEnd();
} }
await server.StopAsync();
} }
Assert.True(foundMessage, "Expected log not found"); 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 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"); "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"); "hello, world");
} }
await server.StopAsync();
} }
} }
@ -1880,6 +1924,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
""); "");
} }
await server.StopAsync();
} }
Assert.False(onStartingCalled); 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, // The first registered OnStarting callback should have been called,
@ -1986,6 +2032,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.
@ -2029,6 +2076,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello World"); "Hello World");
} }
await server.StopAsync();
} }
Assert.True(onStartingCalled); Assert.True(onStartingCalled);
@ -2070,6 +2118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello"); "Hello");
} }
await server.StopAsync();
} }
Assert.True(onStartingCalled); Assert.True(onStartingCalled);
@ -2103,6 +2152,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));
@ -2128,6 +2178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
""); "");
await connection.ReceiveEnd(); 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. // 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());
@ -2277,6 +2330,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());
@ -2331,6 +2385,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello2"); "Hello2");
} }
await server.StopAsync();
} }
} }
@ -2370,6 +2425,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"", "",
"Hello!"); "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(); 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();
} }
} }
} }