diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs index 0caf5e5101..993ea06aa7 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -1,8 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; @@ -125,6 +127,50 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests } } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on mono.")] + public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() + { + var config = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "server.urls", "http://localhost:8794/" } + }) + .Build(); + + var onStartingCalled = false; + var onCompletedCalled = false; + + var hostBuilder = new WebApplicationBuilder() + .UseConfiguration(config) + .UseServer("Microsoft.AspNet.Server.Kestrel") + .Configure(app => + { + app.Run(context => + { + context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); + context.Response.OnCompleted(() => Task.Run(() => onCompletedCalled = true)); + + // Prevent OnStarting call (see Frame.RequestProcessingAsync()). + throw new Exception(); + }); + }); + + using (var app = hostBuilder.Build()) + { + app.Start(); + + using (var client = new HttpClient()) + { + var response = await client.GetAsync("http://localhost:8794/"); + + Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); + Assert.False(onStartingCalled); + Assert.True(onCompletedCalled); + } + } + } + public static TheoryData NullHeaderData { get