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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
379 additions
and
15 deletions.
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
33 changes: 33 additions & 0 deletions
33
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,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}"); | ||
} | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>fc578f4e-171c-4f82-b301-3abf6318d082</ProjectGuid> | ||
<RootNamespace>Microsoft.AspNetCore.Hosting.FunctionalTests</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
106 changes: 106 additions & 0 deletions
106
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,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); | ||
} | ||
} | ||
} |
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" | ||
} |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>542d4600-b232-4b17-a08c-e31ebfa0d74e</ProjectGuid> | ||
<RootNamespace>Microsoft.AspNetCore.Hosting.TestSites</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.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,49 @@ | ||
// 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) | ||
.UseKestrel() | ||
.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.Set(); | ||
} | ||
|
||
public IFeatureCollection Features { get; } = new FeatureCollection(); | ||
|
||
public void Start<TContext>(IHttpApplication<TContext> application) | ||
{ | ||
_serverEvent.Wait(); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.