From 4e7de6ab458b0b08d5d4d6cdd95daaf592871f78 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 2 Nov 2016 13:55:42 -0700 Subject: [PATCH 1/8] Add test for SIGTERM functionality --- Hosting.sln | 33 +++++- .../Deployers/SelfHostDeployer.cs | 26 ++--- .../project.json | 1 + .../xunit/TestProjectHelpers.cs | 33 ++++++ ...t.AspNetCore.Hosting.FunctionalTests.xproj | 19 ++++ .../ShutdownTests.cs | 106 ++++++++++++++++++ .../project.json | 34 ++++++ ...crosoft.AspNetCore.Hosting.TestSites.xproj | 19 ++++ .../Program.cs | 48 ++++++++ .../StartupShutdown.cs | 37 ++++++ .../project.json | 36 ++++++ 11 files changed, 377 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs create mode 100644 test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj create mode 100644 test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs create mode 100644 test/Microsoft.AspNetCore.Hosting.FunctionalTests/project.json create mode 100644 test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj create mode 100644 test/Microsoft.AspNetCore.Hosting.TestSites/Program.cs create mode 100644 test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs create mode 100644 test/Microsoft.AspNetCore.Hosting.TestSites/project.json diff --git a/Hosting.sln b/Hosting.sln index e00cee06..96a30a67 100644 --- a/Hosting.sln +++ b/Hosting.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}" EndProject @@ -32,6 +31,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SampleStartups", "samples\S EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.WindowsServices", "src\Microsoft.AspNetCore.Hosting.WindowsServices\Microsoft.AspNetCore.Hosting.WindowsServices.xproj", "{03148731-EA95-40A2-BAE8-A12315EA1748}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.FunctionalTests", "test\Microsoft.AspNetCore.Hosting.FunctionalTests\Microsoft.AspNetCore.Hosting.FunctionalTests.xproj", "{FC578F4E-171C-4F82-B301-3ABF6318D082}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Hosting.TestSites", "test\Microsoft.AspNetCore.Hosting.TestSites\Microsoft.AspNetCore.Hosting.TestSites.xproj", "{542D4600-B232-4B17-A08C-E31EBFA0D74E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -142,6 +145,30 @@ Global {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|Mixed Platforms.Build.0 = Release|Any CPU {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|x86.ActiveCfg = Release|Any CPU {03148731-EA95-40A2-BAE8-A12315EA1748}.Release|x86.Build.0 = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|x86.ActiveCfg = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Debug|x86.Build.0 = Debug|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|Any CPU.Build.0 = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|x86.ActiveCfg = Release|Any CPU + {FC578F4E-171C-4F82-B301-3ABF6318D082}.Release|x86.Build.0 = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|x86.ActiveCfg = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Debug|x86.Build.0 = Debug|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|Any CPU.Build.0 = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|x86.ActiveCfg = Release|Any CPU + {542D4600-B232-4B17-A08C-E31EBFA0D74E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -156,5 +183,7 @@ Global {3DA89347-6731-4366-80C4-548F24E8607B} = {E0497F39-AFFB-4819-A116-E39E361915AB} {485B6745-7648-400A-A969-F68FCF194E46} = {9C7520A0-F2EB-411C-8BB2-80B39C937217} {03148731-EA95-40A2-BAE8-A12315EA1748} = {E0497F39-AFFB-4819-A116-E39E361915AB} + {FC578F4E-171C-4F82-B301-3ABF6318D082} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} + {542D4600-B232-4B17-A08C-E31EBFA0D74E} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs index 7148c6fb..d7764c02 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting /// public class SelfHostDeployer : ApplicationDeployer { - private Process _hostProcess; + public Process HostProcess { get; private set; } public SelfHostDeployer(DeploymentParameters deploymentParameters, ILogger logger) : base(deploymentParameters, logger) @@ -103,32 +103,32 @@ protected CancellationToken StartSelfHost(Uri uri) AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables); - _hostProcess = new Process() { StartInfo = startInfo }; - _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; - _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; - _hostProcess.EnableRaisingEvents = true; + HostProcess = new Process() { StartInfo = startInfo }; + HostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); }; + HostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); }; + HostProcess.EnableRaisingEvents = true; var hostExitTokenSource = new CancellationTokenSource(); - _hostProcess.Exited += (sender, e) => + HostProcess.Exited += (sender, e) => { TriggerHostShutdown(hostExitTokenSource); }; - _hostProcess.Start(); - _hostProcess.BeginErrorReadLine(); - _hostProcess.BeginOutputReadLine(); + HostProcess.Start(); + HostProcess.BeginErrorReadLine(); + HostProcess.BeginOutputReadLine(); - if (_hostProcess.HasExited) + if (HostProcess.HasExited) { - Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, _hostProcess.ExitCode); + Logger.LogError("Host process {processName} exited with code {exitCode} or failed to start.", startInfo.FileName, HostProcess.ExitCode); throw new Exception("Failed to start host"); } - Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, _hostProcess.Id); + Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, HostProcess.Id); return hostExitTokenSource.Token; } public override void Dispose() { - ShutDownIfAnyHostProcess(_hostProcess); + ShutDownIfAnyHostProcess(HostProcess); if (DeploymentParameters.PublishApplicationBeforeDeployment) { diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/project.json b/src/Microsoft.AspNetCore.Server.IntegrationTesting/project.json index 98b6d395..a7e2cb5e 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/project.json +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/project.json @@ -32,6 +32,7 @@ "type": "build", "version": "1.1.0-*" }, + "Microsoft.Extensions.PlatformAbstractions": "1.1.0-*", "NETStandard.Library": "1.6.1-*" }, "frameworks": { diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs new file mode 100644 index 00000000..cb5a38c5 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs @@ -0,0 +1,33 @@ +// 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.IO; +using Microsoft.Extensions.PlatformAbstractions; + +namespace Microsoft.AspNetCore.Server.IntegrationTesting.xunit +{ + public class TestProjectHelpers + { + public static string GetProjectRoot() + { + var applicationBasePath = PlatformServices.Default.Application.ApplicationBasePath; + + var directoryInfo = new DirectoryInfo(applicationBasePath); + do + { + var projectFileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, "project.json")); + if (projectFileInfo.Exists) + { + return projectFileInfo.DirectoryName; + } + + directoryInfo = directoryInfo.Parent; + } + while (directoryInfo.Parent != null); + + throw new Exception($"Project root could not be found using {applicationBasePath}"); + } + + } + } diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj new file mode 100644 index 00000000..c7cab6d7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj @@ -0,0 +1,19 @@ + + + + 14.0.25420 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + fc578f4e-171c-4f82-b301-3abf6318d082 + Microsoft.AspNetCore.Hosting.FunctionalTests + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs new file mode 100644 index 00000000..a0989f85 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -0,0 +1,106 @@ +// 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.Diagnostics; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.xunit; +using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging; +using Xunit; +using Xunit.Sdk; + +namespace Microsoft.AspNetCore.Hosting.FunctionalTests +{ + public class ShutdownTests + { + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Windows)] + public async Task ShutdownTest() + { + var logger = new LoggerFactory() + .AddConsole() + .CreateLogger(nameof(ShutdownTest)); + + string applicationPath = Path.Combine(TestProjectHelpers.GetProjectRoot(), "..", + "Microsoft.AspNetCore.Hosting.TestSites"); + + var deploymentParameters = new DeploymentParameters( + applicationPath, + ServerType.Kestrel, + RuntimeFlavor.CoreClr, + RuntimeArchitecture.x64) + { + EnvironmentName = "Shutdown", + TargetFramework = "netcoreapp1.1", + ApplicationType = ApplicationType.Portable, + PublishApplicationBeforeDeployment = true + }; + + using (var deployer = new SelfHostDeployer(deploymentParameters, logger)) + { + var deploymentResult = deployer.Deploy(); + var httpClientHandler = new HttpClientHandler(); + var httpClient = new HttpClient(httpClientHandler) + { + BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) + }; + + var response = await RetryHelper.RetryRequest( + () => httpClient.GetAsync(string.Empty), + logger, + deploymentResult.HostShutdownToken); + + var responseText = await response.Content.ReadAsStringAsync(); + try + { + Assert.Equal("Hello World", responseText); + } + catch (XunitException) + { + logger.LogWarning(response.ToString()); + logger.LogWarning(responseText); + throw; + } + + string output = string.Empty; + deployer.HostProcess.OutputDataReceived += (sender, args) => output += args.Data + '\n'; + + SendSIGINT(deployer.HostProcess.Id); + + deployer.HostProcess.WaitForExit(); + output = output.Trim('\n'); + + Assert.Equal(output, "Application is shutting down...\n" + + "Stopping firing\n" + + "Stopping end\n" + + "Stopped firing\n" + + "Stopped end"); + } + } + + + private static void SendSIGINT(int processId) + { + var startInfo = new ProcessStartInfo + { + FileName = "kill", + Arguments = processId.ToString(), + RedirectStandardOutput = true, + UseShellExecute = false + }; + + var process = Process.Start(startInfo); + process.WaitForExit(1000); + if (!process.HasExited) + { + process.Kill(); + } + + Assert.Equal(0, process.ExitCode); + } + } +} diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/project.json b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/project.json new file mode 100644 index 00000000..0abc059b --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/project.json @@ -0,0 +1,34 @@ +{ + "buildOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk", + "copyToOutput": { + "include": [ + "testroot/**/*" + ] + } + }, + "publishOptions": { + "include": [ + "testroot/**/*" + ] + }, + "dependencies": { + "dotnet-test-xunit": "2.2.0-*", + "Microsoft.AspNetCore.Server.IntegrationTesting": "0.2.0-*", + "Microsoft.AspNetCore.Hosting": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*", + "xunit": "2.2.0-*" + }, + "frameworks": { + "netcoreapp1.1": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.1.0-*", + "type": "platform" + } + } + } + }, + "testRunner": "xunit" +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj new file mode 100644 index 00000000..f9f6049a --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj @@ -0,0 +1,19 @@ + + + + 14.0.25420 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 542d4600-b232-4b17-a08c-e31ebfa0d74e + Microsoft.AspNetCore.Hosting.TestSites + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/Program.cs b/test/Microsoft.AspNetCore.Hosting.TestSites/Program.cs new file mode 100644 index 00000000..6c30ca77 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/Program.cs @@ -0,0 +1,48 @@ +// 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 Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using System.Threading; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; + +namespace ServerComparison.TestSites +{ + public static class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .Build(); + + var builder = new WebHostBuilder() + .UseServer(new NoopServer()) + .UseConfiguration(config) + .UseStartup("Microsoft.AspNetCore.Hosting.TestSites"); + + var host = builder.Build(); + + host.Run(); + } + } + + public class NoopServer : IServer + { + private readonly ManualResetEventSlim _serverEvent = new ManualResetEventSlim(false); + + public void Dispose() + { + _serverEvent.Wait(); + } + + public IFeatureCollection Features { get; } = new FeatureCollection(); + + public void Start(IHttpApplication application) + { + _serverEvent.Set(); + } + } +} + diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs b/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs new file mode 100644 index 00000000..e71b5a7a --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs @@ -0,0 +1,37 @@ +// 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 Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Hosting.TestSites +{ + public class StartupShutdown + { + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationLifetime lifetime) + { + lifetime.ApplicationStopping.Register(() => + { + Console.WriteLine("Stopping firing"); + System.Threading.Thread.Sleep(1000); + Console.WriteLine("Stopping end"); + }); + lifetime.ApplicationStopped.Register(() => + { + Console.WriteLine("Stopped firing"); + System.Threading.Thread.Sleep(1000); + Console.WriteLine("Stopped end"); + }); + + + loggerFactory.AddConsole(minLevel: LogLevel.Warning); + + app.Run(context => + { + return context.Response.WriteAsync("Hello World"); + }); + } + } +} diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/project.json b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json new file mode 100644 index 00000000..ba1229f6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json @@ -0,0 +1,36 @@ +{ + "version": "1.1.0-*", + "dependencies": { + "Microsoft.AspNetCore.Hosting": "1.1.0-*", + "Microsoft.AspNetCore.WebUtilities": "1.1.0-*", + "Microsoft.Extensions.Configuration": "1.1.0-*", + "Microsoft.Extensions.Configuration.CommandLine": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*", + "Microsoft.Net.Http.Headers": "1.1.0-*" + }, + "buildOptions": { + "emitEntryPoint": true + }, + "publishOptions": { + "include": [ + "web.config" + ] + }, + "frameworks": { + "net451": {}, + "netcoreapp1.1": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.1.0-*", + "type": "platform" + } + } + } + }, + "tools": { + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" + }, + "scripts": { + "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" + } +} \ No newline at end of file From 37388c7b70dcbf01bb29903369fb4bde92778907 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 10:21:58 -0700 Subject: [PATCH 2/8] Works on linux --- .../ShutdownTests.cs | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs index a0989f85..9074ec08 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -19,7 +19,7 @@ public class ShutdownTests { [ConditionalFact] [OSSkipCondition(OperatingSystems.Windows)] - public async Task ShutdownTest() + public void ShutdownTest() { var logger = new LoggerFactory() .AddConsole() @@ -43,30 +43,10 @@ public async Task ShutdownTest() using (var deployer = new SelfHostDeployer(deploymentParameters, logger)) { var deploymentResult = deployer.Deploy(); - var httpClientHandler = new HttpClientHandler(); - var httpClient = new HttpClient(httpClientHandler) - { - BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) - }; - - var response = await RetryHelper.RetryRequest( - () => httpClient.GetAsync(string.Empty), - logger, - deploymentResult.HostShutdownToken); - - var responseText = await response.Content.ReadAsStringAsync(); - try - { - Assert.Equal("Hello World", responseText); - } - catch (XunitException) - { - logger.LogWarning(response.ToString()); - logger.LogWarning(responseText); - throw; - } - string output = string.Empty; + + System.Threading.Thread.Sleep(1000); + deployer.HostProcess.OutputDataReceived += (sender, args) => output += args.Data + '\n'; SendSIGINT(deployer.HostProcess.Id); From 60960ae533c9d7df8cc938e5574d87530bfe4a76 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 10:43:26 -0700 Subject: [PATCH 3/8] Smaller waits --- .../ShutdownTests.cs | 7 ++++--- .../StartupShutdown.cs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs index 9074ec08..2b02c876 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -42,11 +42,12 @@ public void ShutdownTest() using (var deployer = new SelfHostDeployer(deploymentParameters, logger)) { - var deploymentResult = deployer.Deploy(); - string output = string.Empty; - + deployer.Deploy(); + + // Wait for application to start System.Threading.Thread.Sleep(1000); + string output = string.Empty; deployer.HostProcess.OutputDataReceived += (sender, args) => output += args.Data + '\n'; SendSIGINT(deployer.HostProcess.Id); diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs b/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs index e71b5a7a..b8a5b8b7 100644 --- a/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/StartupShutdown.cs @@ -15,13 +15,13 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IAp lifetime.ApplicationStopping.Register(() => { Console.WriteLine("Stopping firing"); - System.Threading.Thread.Sleep(1000); + System.Threading.Thread.Sleep(200); Console.WriteLine("Stopping end"); }); lifetime.ApplicationStopped.Register(() => { Console.WriteLine("Stopped firing"); - System.Threading.Thread.Sleep(1000); + System.Threading.Thread.Sleep(200); Console.WriteLine("Stopped end"); }); From d8bd88ea27690b329b2c107330167b8d15346f3f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 11:38:16 -0700 Subject: [PATCH 4/8] Disable on macOS --- .../xunit/TestProjectHelpers.cs | 1 - .../ShutdownTests.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs index cb5a38c5..76a3dc6d 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs @@ -28,6 +28,5 @@ public static string GetProjectRoot() throw new Exception($"Project root could not be found using {applicationBasePath}"); } - } } diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs index 2b02c876..d40c1755 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -19,6 +19,7 @@ public class ShutdownTests { [ConditionalFact] [OSSkipCondition(OperatingSystems.Windows)] + [OSSkipCondition(OperatingSystems.MacOSX)] public void ShutdownTest() { var logger = new LoggerFactory() From fcdbbdf1db92101498fd36fbadf07bbde9bdb73f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 11:57:16 -0700 Subject: [PATCH 5/8] Make sure we kill host process if it hangs, clean dependencies --- .../ShutdownTests.cs | 8 +++++++- test/Microsoft.AspNetCore.Hosting.TestSites/project.json | 2 -- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs index d40c1755..c794cbc9 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -53,7 +53,8 @@ public void ShutdownTest() SendSIGINT(deployer.HostProcess.Id); - deployer.HostProcess.WaitForExit(); + WaitForExitOrKill(deployer.HostProcess); + output = output.Trim('\n'); Assert.Equal(output, "Application is shutting down...\n" + @@ -76,6 +77,11 @@ private static void SendSIGINT(int processId) }; var process = Process.Start(startInfo); + WaitForExitOrKill(process); + } + + private static void WaitForExitOrKill(Process process) + { process.WaitForExit(1000); if (!process.HasExited) { diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/project.json b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json index ba1229f6..02b0cfb9 100644 --- a/test/Microsoft.AspNetCore.Hosting.TestSites/project.json +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json @@ -2,11 +2,9 @@ "version": "1.1.0-*", "dependencies": { "Microsoft.AspNetCore.Hosting": "1.1.0-*", - "Microsoft.AspNetCore.WebUtilities": "1.1.0-*", "Microsoft.Extensions.Configuration": "1.1.0-*", "Microsoft.Extensions.Configuration.CommandLine": "1.1.0-*", "Microsoft.Extensions.Logging.Console": "1.1.0-*", - "Microsoft.Net.Http.Headers": "1.1.0-*" }, "buildOptions": { "emitEntryPoint": true From c0f52a9cb9be97079d17dfb162e32f4297f74ed2 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 15:14:16 -0700 Subject: [PATCH 6/8] Cleanup xproj files --- .../Microsoft.AspNetCore.Hosting.FunctionalTests.xproj | 10 ++++------ .../Microsoft.AspNetCore.Hosting.TestSites.xproj | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj index c7cab6d7..3e17cac8 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj @@ -1,19 +1,17 @@  - + - 14.0.25420 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + fc578f4e-171c-4f82-b301-3abf6318d082 - Microsoft.AspNetCore.Hosting.FunctionalTests .\obj .\bin\ - 2.0 - + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj index f9f6049a..05732b74 100644 --- a/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj @@ -1,19 +1,17 @@  - + - 14.0.25420 + 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 542d4600-b232-4b17-a08c-e31ebfa0d74e - Microsoft.AspNetCore.Hosting.TestSites .\obj .\bin\ - 2.0 - + \ No newline at end of file From 6ebea6d65f31034eb99a798e3b0cbc8c3c22f0c7 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 15:22:13 -0700 Subject: [PATCH 7/8] Remove NoopServer implementation --- .../.Program.cs.swp | Bin 0 -> 12288 bytes .../Program.cs | 4 ---- 2 files changed, 4 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Hosting.TestSites/.Program.cs.swp diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/.Program.cs.swp b/test/Microsoft.AspNetCore.Hosting.TestSites/.Program.cs.swp new file mode 100644 index 0000000000000000000000000000000000000000..ef1c7881b16b651bf2b0d03796b39adca14116ad GIT binary patch literal 12288 zcmeI2O>fjj7{`a+NDEXT^@5Nd5)NL8%!U`0mH^VS4J8r@h)n_rRh8GCYz(^|Yi1l0 zrL<}fh;z^707v)=y;TBwg?@s51P+}0AKQ!BE(u&g&q)6r+w=H&`OVBKt4w!hWqyH9 z$&&)@OCetGK6L%j#ESU#sSsIs+iVW}z|O6-o6fs=>hfb>Z)^N>Y1q7|txM8g(<$qk z3rS?O)vHdnY__OeTN@=S3%LY~P6E5;6{CA59LUIS>z)Ug02A1bK<-wjzu6;B96vVW zO{OLf(}DfV+gbB-Ccp%k025#WOn?b60Vco%K0yL5+a-QMU7uC89j*FZ|Ldz;?w9}* zU;<2l2`~XBzyz286JP>NfC(^xkB~qZ3-Mq=h~#r5kN^JJvQQYSmg1&vwZM||57MTd_p@Ai|3)^!q7$A!k7S!(OlsSP3C zAK?8aJ6L=`4(?nqf6=+Dm1RgWbcs%f>A7=yIdly5Cokf0L>w zmbR#;+$`Otvy`ek!{@c7C-uf(4fx#&f0x)yTNN~lH%gl-ho~P~ON&}(onk8JG|iV+ zrTf}-edViI!%1OzHBU$K@B{0iDF%^vH&6PpGV;9d#|*u(T(+v1(L4(#KkU5mR=-?U%gN+fa(yp*b-?tP&NxAMddO;+F584tJC_-H-21N_@;Ny7&e0(uH)GqEz8s9 z*!ccSU})Oev`!7=(wb3Wj3~qBb+EY&r&5dUV&w>>am(?8>)18TCS6J*cu+CrDHbTX zHAOAdjIJ6vN-N6v5OiG5NT7H#BHf0gBrV>_jJ}19OGax)tJ)C00lZ&~<8DwaMd{(IHttpApplication application) { - _serverEvent.Set(); } } } From 877ef71ff3c5cbdfb0bb98e542d27b63c65f9719 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 4 Nov 2016 15:29:42 -0700 Subject: [PATCH 8/8] Cleanup project.json --- .../project.json | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/project.json b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json index 02b0cfb9..5dc04cc3 100644 --- a/test/Microsoft.AspNetCore.Hosting.TestSites/project.json +++ b/test/Microsoft.AspNetCore.Hosting.TestSites/project.json @@ -4,16 +4,11 @@ "Microsoft.AspNetCore.Hosting": "1.1.0-*", "Microsoft.Extensions.Configuration": "1.1.0-*", "Microsoft.Extensions.Configuration.CommandLine": "1.1.0-*", - "Microsoft.Extensions.Logging.Console": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*" }, "buildOptions": { "emitEntryPoint": true }, - "publishOptions": { - "include": [ - "web.config" - ] - }, "frameworks": { "net451": {}, "netcoreapp1.1": { @@ -24,11 +19,5 @@ } } } - }, - "tools": { - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" - }, - "scripts": { - "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" } -} \ No newline at end of file +}