Skip to content

Commit

Permalink
Add server abort tests (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym committed Oct 15, 2018
1 parent df51be4 commit b0deed0
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 32 deletions.
11 changes: 6 additions & 5 deletions build/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"commandName": "Executable",
"executablePath": "$(IISExpressPath)",
"commandLineArgs": "$(IISExpressArguments)",
"nativeDebugging": true,
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(TargetDir)\\$(AncmPath)",
"ANCMV2_PATH": "$(TargetDir)\\$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand All @@ -29,8 +29,9 @@
"commandLineArgs": "$(IISArguments)",
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand Down
2 changes: 0 additions & 2 deletions build/testsite.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
<IISExpressArguments>/config:"$(IISExpressAppHostConfig)" /systray:false</IISExpressArguments>
<IISArguments>-h "$(IISAppHostConfig)"</IISArguments>

<AncmPath>$(AspNetCoreModuleV1ShimDll)</AncmPath>
<AncmV2Path>$(AspNetCoreModuleV2ShimDll)</AncmV2Path>
<AncmInProcessRHPath>aspnetcorev2_inprocess.dll</AncmInProcessRHPath>
<DotNetPath>$(userprofile)\.dotnet\$(NativePlatform)\dotnet.exe</DotNetPath>
</PropertyGroup>
Expand Down
7 changes: 4 additions & 3 deletions samples/NativeIISSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"commandName": "Executable",
"executablePath": "$(IISExpressPath)",
"commandLineArgs": "$(IISExpressArguments)",
"nativeDebugging": true,
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(TargetDir)\\$(AncmPath)",
"ANCMV2_PATH": "$(TargetDir)\\$(AncmV2Path)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand All @@ -31,6 +31,7 @@
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand Down
14 changes: 11 additions & 3 deletions src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "WebConfigConfigurationSource.h"
#include "ModuleHelpers.h"
#include "BaseOutputManager.h"
#include "Environment.h"

const PCWSTR HandlerResolver::s_pwzAspnetcoreInProcessRequestHandlerName = L"aspnetcorev2_inprocess.dll";
const PCWSTR HandlerResolver::s_pwzAspnetcoreOutOfProcessRequestHandlerName = L"aspnetcorev2_outofprocess.dll";
Expand Down Expand Up @@ -103,12 +104,12 @@ HandlerResolver::LoadRequestHandlerAssembly(const IHttpApplication &pApplication
LOG_INFOF(L"Loading request handler: '%ls'", handlerDllPath.c_str());

hRequestHandlerDll = LoadLibrary(handlerDllPath.c_str());
RETURN_LAST_ERROR_IF_NULL(hRequestHandlerDll);
if (preventUnload)
{
// Pin module in memory
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, pstrHandlerDllName, &hRequestHandlerDll);
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, handlerDllPath.c_str(), &hRequestHandlerDll);
}
RETURN_LAST_ERROR_IF_NULL(hRequestHandlerDll);
}

auto pfnAspNetCoreCreateApplication = ModuleHelpers::GetKnownProcAddress<PFN_ASPNETCORE_CREATE_APPLICATION>(hRequestHandlerDll, "CreateApplication");
Expand Down Expand Up @@ -150,7 +151,7 @@ HandlerResolver::GetApplicationFactory(const IHttpApplication &pApplication, std
m_loadedApplicationHostingModel = options.QueryHostingModel();
m_loadedApplicationId = pApplication.GetApplicationId();
RETURN_IF_FAILED(LoadRequestHandlerAssembly(pApplication, options, pApplicationFactory));

return S_OK;
}

Expand All @@ -171,6 +172,13 @@ HandlerResolver::FindNativeAssemblyFromGlobalLocation(
{
try
{
auto handlerPath = Environment::GetEnvironmentVariableValue(L"ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER");
if (handlerPath.has_value() && std::filesystem::is_regular_file(handlerPath.value()))
{
handlerDllPath = handlerPath.value();
return S_OK;
}

std::wstring modulePath = GlobalVersionUtility::GetModuleName(m_hModule);

modulePath = GlobalVersionUtility::RemoveFileNameFromFolderPath(modulePath);
Expand Down
1 change: 0 additions & 1 deletion test/Common.FunctionalTests/BasicAuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.IIS;
Expand Down
2 changes: 1 addition & 1 deletion test/Common.FunctionalTests/Inprocess/FixtureLoggedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public FixtureLoggedTest(IISTestSiteFixture fixture)
{
_fixture = fixture;
}

public override void Initialize(MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper)
{
base.Initialize(methodInfo, testMethodArguments, testOutputHelper);
Expand Down
65 changes: 65 additions & 0 deletions test/Common.FunctionalTests/ServerAbortTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{
public abstract class ServerAbortTests: FixtureLoggedTest
{
private readonly IISTestSiteFixture _fixture;

[Collection(IISTestSiteCollection.Name)]
public class InProc: ServerAbortTests
{
public InProc(IISTestSiteFixture fixture) : base(fixture) { }
}

[Collection(OutOfProcessTestSiteCollection.Name)]
public class OutOfProcess: ServerAbortTests
{
public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { }
}

[Collection(OutOfProcessV1TestSiteCollection.Name)]
public class OutOfProcessV1: ServerAbortTests
{
public OutOfProcessV1(OutOfProcessV1TestSiteFixture fixture) : base(fixture) { }
}

protected ServerAbortTests(IISTestSiteFixture fixture) : base(fixture)
{
_fixture = fixture;
}

[ConditionalFact]
public async Task ClosesConnectionOnServerAbort()
{
try
{
var response = await _fixture.Client.GetAsync("/Abort").DefaultTimeout();

// 502 is expected for outofproc but not for inproc
if (_fixture.DeploymentResult.DeploymentParameters.HostingModel == HostingModel.OutOfProcess)
{
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
// 0x80072f78 ERROR_HTTP_INVALID_SERVER_RESPONSE The server returned an invalid or unrecognized response
Assert.Contains("0x80072f78", await response.Content.ReadAsStringAsync());
}
else
{
Assert.True(false, "Should not reach here");
}
}
catch (HttpRequestException)
{
// Connection reset is expected both for outofproc and inproc
}
}
}
}
13 changes: 13 additions & 0 deletions test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@ public class IISTestSiteCollection : ICollectionFixture<IISTestSiteFixture>
{
public const string Name = nameof(IISTestSiteCollection);
}

[CollectionDefinition(Name)]
public class OutOfProcessTestSiteCollection : ICollectionFixture<OutOfProcessTestSiteFixture>
{
public const string Name = nameof(OutOfProcessTestSiteCollection);
}

[CollectionDefinition(Name)]
public class OutOfProcessV1TestSiteCollection : ICollectionFixture<OutOfProcessV1TestSiteFixture>
{
public const string Name = nameof(OutOfProcessV1TestSiteCollection);
}

}
28 changes: 27 additions & 1 deletion test/Common.FunctionalTests/Utilities/IISTestSiteFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.IIS;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;

namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
{
public class OutOfProcessTestSiteFixture : IISTestSiteFixture
{
public OutOfProcessTestSiteFixture() : base(Configure)
{
}

private static void Configure(IISDeploymentParameters deploymentParameters)
{
deploymentParameters.ApplicationPath = Helpers.GetOutOfProcessTestSitesPath();
deploymentParameters.HostingModel = HostingModel.OutOfProcess;
}
}

public class OutOfProcessV1TestSiteFixture : IISTestSiteFixture
{
public OutOfProcessV1TestSiteFixture() : base(Configure)
{
}

private static void Configure(IISDeploymentParameters deploymentParameters)
{
deploymentParameters.ApplicationPath = Helpers.GetOutOfProcessTestSitesPath();
deploymentParameters.HostingModel = HostingModel.OutOfProcess;
deploymentParameters.AncmVersion = AncmVersion.AspNetCoreModule;
}
}

public class IISTestSiteFixture : IDisposable
{
private ApplicationDeployer _deployer;
Expand Down
30 changes: 30 additions & 0 deletions test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 System.Linq;
using System.Net;
Expand Down Expand Up @@ -52,6 +53,35 @@ public async Task GlobalVersion_DefaultWorks()
Assert.Equal(_helloWorldResponse, responseText);
}

[ConditionalFact]
[RequiresIIS(IISCapability.PoolEnvironmentVariables)]
public async Task GlobalVersion_EnvironmentVariableWorks()
{
var temporaryFile = Path.GetTempFileName();
try
{
var deploymentParameters = GetGlobalVersionBaseDeploymentParameters();
CopyShimToOutput(deploymentParameters);
deploymentParameters.PublishApplicationBeforeDeployment = true;
deploymentParameters.EnvironmentVariables["ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER"] = temporaryFile;

var deploymentResult = await DeployAsync(deploymentParameters);
var requestHandlerPath = Path.Combine(GetANCMRequestHandlerPath(deploymentResult, _handlerVersion20), "aspnetcorev2_outofprocess.dll");

File.Delete(temporaryFile);
File.Move(requestHandlerPath, temporaryFile);

var response = await deploymentResult.HttpClient.GetAsync(_helloWorldRequest);
var responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(_helloWorldResponse, responseText);
StopServer();
}
finally
{
File.Delete(temporaryFile);
}
}

[ConditionalTheory]
[InlineData("2.1.0")]
[InlineData("2.1.0-preview")]
Expand Down
11 changes: 6 additions & 5 deletions test/WebSites/InProcessWebSite/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"commandName": "Executable",
"executablePath": "$(IISExpressPath)",
"commandLineArgs": "$(IISExpressArguments)",
"nativeDebugging": true,
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(TargetDir)\\$(AncmPath)",
"ANCMV2_PATH": "$(TargetDir)\\$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand All @@ -29,8 +29,9 @@
"commandLineArgs": "$(IISArguments)",
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand Down
11 changes: 6 additions & 5 deletions test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"commandName": "Executable",
"executablePath": "$(IISExpressPath)",
"commandLineArgs": "$(IISExpressArguments)",
"nativeDebugging": true,
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(TargetDir)\\$(AncmPath)",
"ANCMV2_PATH": "$(TargetDir)\\$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand All @@ -29,8 +29,9 @@
"commandLineArgs": "$(IISArguments)",
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand Down
11 changes: 6 additions & 5 deletions test/WebSites/StressTestWebSite/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"commandName": "Executable",
"executablePath": "$(IISExpressPath)",
"commandLineArgs": "$(IISExpressArguments)",
"nativeDebugging": true,
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(TargetDir)\\$(AncmPath)",
"ANCMV2_PATH": "$(TargetDir)\\$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand All @@ -29,8 +29,9 @@
"commandLineArgs": "$(IISArguments)",
"environmentVariables": {
"IIS_SITE_PATH": "$(MSBuildThisFileDirectory)",
"ANCM_PATH": "$(AncmPath)",
"ANCMV2_PATH": "$(AncmV2Path)",
"ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)",
"ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)",
"ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)",
"LAUNCHER_ARGS": "$(TargetPath)",
"ASPNETCORE_ENVIRONMENT": "Development",
"LAUNCHER_PATH": "$(DotNetPath)",
Expand Down
8 changes: 7 additions & 1 deletion test/WebSites/shared/SharedStartup/Startup.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ public Task WaitForAbort(HttpContext context)
}
finally
{
Interlocked.Decrement(ref _waitingRequestCount);
Interlocked.Decrement(ref _waitingRequestCount);
}
}

public Task Abort(HttpContext context)
{
context.Abort();
return Task.CompletedTask;
}

public async Task WaitingRequestCount(HttpContext context)
{
await context.Response.WriteAsync(_waitingRequestCount.ToString());
Expand Down

0 comments on commit b0deed0

Please sign in to comment.