This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
Add test for SIGTERM functionality #878
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e7de6a
Add test for SIGTERM functionality
pakrym 37388c7
Works on linux
pakrym 60960ae
Smaller waits
pakrym d8bd88e
Disable on macOS
pakrym fcdbbdf
Make sure we kill host process if it hangs, clean dependencies
pakrym c0f52a9
Cleanup xproj files
pakrym 6ebea6d
Remove NoopServer implementation
pakrym 877ef71
Cleanup project.json
pakrym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Microsoft.AspNetCore.Server.IntegrationTesting/xunit/TestProjectHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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}"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...oft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>fc578f4e-171c-4f82-b301-3abf6318d082</ProjectGuid> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
94 changes: 94 additions & 0 deletions
94
test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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)] | ||
[OSSkipCondition(OperatingSystems.MacOSX)] | ||
public void 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)) | ||
{ | ||
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); | ||
|
||
WaitForExitOrKill(deployer.HostProcess); | ||
|
||
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); | ||
WaitForExitOrKill(process); | ||
} | ||
|
||
private static void WaitForExitOrKill(Process process) | ||
{ | ||
process.WaitForExit(1000); | ||
if (!process.HasExited) | ||
{ | ||
process.Kill(); | ||
} | ||
|
||
Assert.Equal(0, process.ExitCode); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
test/Microsoft.AspNetCore.Hosting.FunctionalTests/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
17 changes: 17 additions & 0 deletions
17
test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>542d4600-b232-4b17-a08c-e31ebfa0d74e</ProjectGuid> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TContext>(IHttpApplication<TContext> application) | ||
{ | ||
_serverEvent.Set(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no guarantee Start will be called if there are other startup errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then process would be killed with timeout. |
||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you query the HostProcess to see if it's started? Why was the delay needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delay is to make sure hosting started IServer.