From 834910964737ebbeaed45a965acd124adb59ab46 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Sun, 17 Mar 2019 10:09:04 -0700 Subject: [PATCH] Atomic swap the request drained handler when shutting down. (#8529) --- .../inprocessapplication.cpp | 7 +- .../inprocessapplication.h | 2 +- .../Common.FunctionalTests/AppOfflineTests.cs | 122 +----------------- .../Common.FunctionalTests/BasicAuthTests.cs | 7 +- .../ClientCertificateTests.cs | 6 +- .../CommonStartupTests.cs | 7 +- .../ConfigurationChangeTests.cs | 15 +-- .../test/Common.FunctionalTests/HttpsTests.cs | 13 +- .../Inprocess/EnvironmentVariableTests.cs | 17 +-- .../Inprocess/ErrorPagesTests.cs | 13 +- .../Inprocess/EventLogTests.cs | 10 +- .../Inprocess/FrebTests.cs | 8 +- .../Inprocess/LogPipeTests.cs | 11 +- .../Inprocess/ShutdownTests.cs | 9 +- .../Inprocess/StartupExceptionTests.cs | 13 +- .../Inprocess/StartupTests.cs | 52 ++++---- .../Common.FunctionalTests/LogFileTests.cs | 23 ++-- .../MultiApplicationTests.cs | 11 +- .../OutOfProcess/AspNetCorePortTests.cs | 11 +- .../OutOfProcess/GlobalVersionTests.cs | 7 +- .../OutOfProcess/HelloWorldTest.cs | 7 +- .../Utilities/IISFunctionalTestBase.cs | 71 +++++++++- .../Utilities/LogFileTestBase.cs | 3 +- .../WindowsAuthTests.cs | 7 +- .../Inprocess/StdOutRedirectionTests.cs | 15 +-- .../ServicesTests.cs | 9 +- .../InProcess/AppOfflineIISExpressTests.cs | 67 ++++++++++ .../InProcess/AuthenticationTests.cs | 7 +- .../InProcess/IISExpressShutdownTests.cs | 12 +- .../OutOfProcess/MultipleAppTests.cs | 7 +- .../OutOfProcess/NtlmAuthentationTest.cs | 7 +- .../UpgradeFeatureDetectionTests.cs | 6 +- 32 files changed, 263 insertions(+), 319 deletions(-) create mode 100644 src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AppOfflineIISExpressTests.cs diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index 8719348843..696211420a 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -560,10 +560,11 @@ IN_PROCESS_APPLICATION::HandleRequestCompletion() void IN_PROCESS_APPLICATION::CallRequestsDrained() { - if (m_RequestsDrainedHandler != nullptr) + // Atomic swap these. + auto handler = m_RequestsDrainedHandler.exchange(nullptr); + if (handler != nullptr) { LOG_INFO(L"Drained all requests, notifying managed."); - m_RequestsDrainedHandler(m_ShutdownHandlerContext); - m_RequestsDrainedHandler = nullptr; + handler(m_ShutdownHandlerContext); } } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h index e6f4c826bb..349b2e2932 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.h @@ -160,7 +160,7 @@ private: PFN_ASYNC_COMPLETION_HANDLER m_AsyncCompletionHandler; PFN_DISCONNECT_HANDLER m_DisconnectHandler; - PFN_REQUESTS_DRAINED_HANDLER m_RequestsDrainedHandler; + std::atomic m_RequestsDrainedHandler; std::wstring m_dotnetExeKnownLocation; diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/AppOfflineTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/AppOfflineTests.cs index 9a46ef82be..5d162a1c3a 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/AppOfflineTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/AppOfflineTests.cs @@ -21,13 +21,8 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class AppOfflineTests : IISFunctionalTestBase { - private static readonly TimeSpan RetryDelay = TimeSpan.FromMilliseconds(100); - - private readonly PublishedSitesFixture _fixture; - - public AppOfflineTests(PublishedSitesFixture fixture) + public AppOfflineTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalTheory] @@ -67,7 +62,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests [InlineData(HostingModel.OutOfProcess, 502, "502.5")] public async Task AppOfflineDroppedWhileSiteFailedToStartInShim_AppOfflineServed(HostingModel hostingModel, int statusCode, string content) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel: hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel: hostingModel); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", "nonexistent")); var deploymentResult = await DeployAsync(deploymentParameters); @@ -99,67 +94,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests await deploymentResult.AssertRecycledAsync(() => AssertAppOffline(deploymentResult)); } - [ConditionalFact] - [RequiresNewHandler] - public async Task AppOfflineDroppedWhileSiteStarting_SiteShutsDown_InProcess() - { - // This test often hits a race between debug logging and stdout redirection closing the handle - // we are fine having this race - using (AppVerifier.Disable(DeployerSelector.ServerType, 0x300)) - { - var deploymentResult = await DeployApp(HostingModel.InProcess); - - for (int i = 0; i < 10; i++) - { - // send first request and add app_offline while app is starting - var runningTask = AssertAppOffline(deploymentResult); - - // This test tries to hit a race where we drop app_offline file while - // in process application is starting, application start takes at least 400ms - // so we back off for 100ms to allow request to reach request handler - // Test itself is racy and can result in two scenarios - // 1. ANCM detects app_offline before it starts the request - if AssertAppOffline succeeds we've hit it - // 2. Intended scenario where app starts and then shuts down - // In first case we remove app_offline and try again - await Task.Delay(RetryDelay); - - AddAppOffline(deploymentResult.ContentRoot); - - try - { - await runningTask.DefaultTimeout(); - - // if AssertAppOffline succeeded ANCM have picked up app_offline before starting the app - // try again - RemoveAppOffline(deploymentResult.ContentRoot); - - if (deploymentResult.DeploymentParameters.ServerType == ServerType.IIS) - { - deploymentResult.AssertWorkerProcessStop(); - return; - } - } - catch - { - // For IISExpress, we need to catch the exception because IISExpress will not restart a process if it crashed. - // RemoveAppOffline will fail due to a bad request exception as the server is down. - Assert.Contains(TestSink.Writes, context => context.Message.Contains("Drained all requests, notifying managed.")); - deploymentResult.AssertWorkerProcessStop(); - return; - } - } - - Assert.True(false); - } - } - [ConditionalFact] public async Task GracefulShutdownWorksWithMultipleRequestsInFlight_InProcess() { // The goal of this test is to have multiple requests currently in progress // and for app offline to be dropped. We expect that all requests are eventually drained // and graceful shutdown occurs. - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} IncreaseShutdownLimit"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -307,62 +248,5 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests } } } - - private async Task DeployApp(HostingModel hostingModel = HostingModel.InProcess) - { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel: hostingModel); - - return await DeployAsync(deploymentParameters); - } - - private void AddAppOffline(string appPath, string content = "The app is offline.") - { - File.WriteAllText(Path.Combine(appPath, "app_offline.htm"), content); - } - - private void RemoveAppOffline(string appPath) - { - RetryHelper.RetryOperation( - () => File.Delete(Path.Combine(appPath, "app_offline.htm")), - e => Logger.LogError($"Failed to remove app_offline : {e.Message}"), - retryCount: 3, - retryDelayMilliseconds: RetryDelay.Milliseconds); - } - - private async Task AssertAppOffline(IISDeploymentResult deploymentResult, string expectedResponse = "The app is offline.") - { - var response = await deploymentResult.HttpClient.RetryRequestAsync("HelloWorld", r => r.StatusCode == HttpStatusCode.ServiceUnavailable); - Assert.Equal(expectedResponse, await response.Content.ReadAsStringAsync()); - } - - private async Task AssertStarts(HostingModel hostingModel) - { - var deploymentResult = await DeployApp(hostingModel); - - await AssertRunning(deploymentResult); - - return deploymentResult; - } - - private static async Task AssertRunning(IISDeploymentResult deploymentResult) - { - var response = await deploymentResult.HttpClient.RetryRequestAsync("HelloWorld", r => r.IsSuccessStatusCode); - var responseText = await response.Content.ReadAsStringAsync(); - Assert.Equal("Hello World", responseText); - } - - private void DeletePublishOutput(IISDeploymentResult deploymentResult) - { - foreach (var file in Directory.GetFiles(deploymentResult.ContentRoot, "*", SearchOption.AllDirectories)) - { - // Out of process module dll is allowed to be locked - var name = Path.GetFileName(file); - if (name == "aspnetcore.dll" || name == "aspnetcorev2.dll" || name == "aspnetcorev2_outofprocess.dll") - { - continue; - } - File.Delete(file); - } - } } } diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/BasicAuthTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/BasicAuthTests.cs index 763ae8f056..c921a4e3dc 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/BasicAuthTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/BasicAuthTests.cs @@ -17,11 +17,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class BasicAuthTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public BasicAuthTests(PublishedSitesFixture fixture) + public BasicAuthTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -39,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var username = Environment.GetEnvironmentVariable("ASPNETCORE_MODULE_TEST_USER"); var password = Environment.GetEnvironmentVariable("ASPNETCORE_MODULE_TEST_PASSWORD"); - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.SetAnonymousAuth(enabled: false); deploymentParameters.SetWindowsAuth(enabled: false); deploymentParameters.SetBasicAuth(enabled: true); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ClientCertificateTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ClientCertificateTests.cs index c1cac0c703..7ba740f0c5 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ClientCertificateTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ClientCertificateTests.cs @@ -20,12 +20,10 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests [SkipIfNotAdmin] public class ClientCertificateTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; private readonly ClientCertificateFixture _certFixture; - public ClientCertificateTests(PublishedSitesFixture fixture, ClientCertificateFixture certFixture) + public ClientCertificateTests(PublishedSitesFixture fixture, ClientCertificateFixture certFixture) : base(fixture) { - _fixture = fixture; _certFixture = certFixture; } @@ -52,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests private async Task ClientCertTest(TestVariant variant, bool sendClientCert) { var port = TestPortHelper.GetNextSSLPort(); - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.ApplicationBaseUriHint = $"https://localhost:{port}/"; deploymentParameters.AddHttpsToServerConfig(); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/CommonStartupTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/CommonStartupTests.cs index 601efbabf5..a7c98be57e 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/CommonStartupTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/CommonStartupTests.cs @@ -13,11 +13,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class CommonStartupTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public CommonStartupTests(PublishedSitesFixture fixture) + public CommonStartupTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -30,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task StartupStress(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ConfigurationChangeTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ConfigurationChangeTests.cs index 5deaa4192e..e8ae38edd2 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ConfigurationChangeTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ConfigurationChangeTests.cs @@ -1,7 +1,6 @@ // 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; @@ -20,18 +19,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class ConfigurationChangeTests : IISFunctionalTestBase { - private static readonly TimeSpan RetryDelay = TimeSpan.FromMilliseconds(100); - private readonly PublishedSitesFixture _fixture; - - public ConfigurationChangeTests(PublishedSitesFixture fixture) + public ConfigurationChangeTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] public async Task ConfigurationChangeStopsInProcess() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.InProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.InProcess); var deploymentResult = await DeployAsync(deploymentParameters); @@ -46,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task ConfigurationChangeForcesChildProcessRestart() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); var deploymentResult = await DeployAsync(deploymentParameters); @@ -63,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task OutOfProcessToInProcessHostingModelSwitchWorks() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); var deploymentResult = await DeployAsync(deploymentParameters); @@ -88,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData(HostingModel.OutOfProcess)] public async Task ConfigurationTouchedStress(HostingModel hostingModel) { - var deploymentResult = await DeployAsync(_fixture.GetBaseDeploymentParameters(hostingModel)); + var deploymentResult = await DeployAsync(Fixture.GetBaseDeploymentParameters(hostingModel)); await deploymentResult.AssertStarts(); var load = Helpers.StressLoad(deploymentResult.HttpClient, "/HelloWorld", response => { diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/HttpsTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/HttpsTests.cs index 3344a38fa8..b2053b5cb1 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/HttpsTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/HttpsTests.cs @@ -19,11 +19,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class HttpsTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public HttpsTests(PublishedSitesFixture fixture) + public HttpsTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -37,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task HttpsHelloWorld(TestVariant variant) { var port = TestPortHelper.GetNextSSLPort(); - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.ApplicationBaseUriHint = $"https://localhost:{port}/"; deploymentParameters.AddHttpsToServerConfig(); @@ -78,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var appName = "\u041C\u043E\u0451\u041F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435"; var port = TestPortHelper.GetNextSSLPort(); - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.InProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.InProcess); deploymentParameters.ApplicationBaseUriHint = $"https://localhost:{port}/"; deploymentParameters.AddHttpsToServerConfig(); deploymentParameters.AddServerConfigAction( @@ -98,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresNewShim] public async Task HttpsPortCanBeOverriden() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); deploymentParameters.AddServerConfigAction( element => { @@ -124,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var sslPort = GetNextSSLPort(); var anotherSslPort = GetNextSSLPort(sslPort); - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); deploymentParameters.AddServerConfigAction( element => { diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EnvironmentVariableTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EnvironmentVariableTests.cs index 153f271d2e..b738155ea6 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EnvironmentVariableTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EnvironmentVariableTests.cs @@ -13,11 +13,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public class EnvironmentVariableTests: IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public EnvironmentVariableTests(PublishedSitesFixture fixture) + public EnvironmentVariableTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalTheory] @@ -33,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests "AReallyLongValueThatIsGreaterThan300CharactersToForceResizeInNative"; - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_INPROCESS_TESTING_LONG_VALUE"] = expectedValue; Assert.Equal( @@ -50,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task AuthHeaderEnvironmentVariableRemoved(HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_IIS_HTTPAUTH"] = "shouldberemoved"; Assert.DoesNotContain("shouldberemoved", await GetStringAsync(deploymentParameters,"/GetEnvironmentVariable?name=ASPNETCORE_IIS_HTTPAUTH")); @@ -67,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task WebConfigOverridesGlobalEnvironmentVariables(HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.EnvironmentVariables["ASPNETCORE_ENVIRONMENT"] = "Development"; deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_ENVIRONMENT"] = "Production"; Assert.Equal("Production", await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=ASPNETCORE_ENVIRONMENT")); @@ -84,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task WebConfigAppendsHostingStartup(HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.EnvironmentVariables["ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"] = "Asm1"; if (hostingModel == HostingModel.InProcess) { @@ -107,7 +104,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task WebConfigOverridesHostingStartup(HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.EnvironmentVariables["ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"] = "Asm1"; deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"] = "Asm2"; Assert.Equal("Asm2", await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=ASPNETCORE_HOSTINGSTARTUPASSEMBLIES")); @@ -124,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task WebConfigExpandsVariables(HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); deploymentParameters.EnvironmentVariables["TestVariable"] = "World"; deploymentParameters.WebConfigBasedEnvironmentVariables["OtherVariable"] = "%TestVariable%;Hello"; Assert.Equal("World;Hello", await GetStringAsync(deploymentParameters, "/GetEnvironmentVariable?name=OtherVariable")); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ErrorPagesTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ErrorPagesTests.cs index ca93fb2c93..12086a3ab9 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ErrorPagesTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ErrorPagesTests.cs @@ -15,18 +15,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class ErrorPagesTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public ErrorPagesTests(PublishedSitesFixture fixture) + public ErrorPagesTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task IncludesAdditionalErrorPageTextInProcessHandlerLoadFailure_CorrectString() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var response = await DeployAppWithStartupFailure(deploymentParameters); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); @@ -44,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task IncludesAdditionalErrorPageTextOutOfProcessStartupFailure_CorrectString() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); var response = await DeployAppWithStartupFailure(deploymentParameters); Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode); @@ -62,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task IncludesAdditionalErrorPageTextOutOfProcessHandlerLoadFailure_CorrectString() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); deploymentParameters.HandlerSettings["handlerVersion"] = "88.93"; deploymentParameters.EnvironmentVariables["ANCM_ADDITIONAL_ERROR_PAGE_LINK"] = "http://example"; @@ -85,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresNewHandler] public async Task IncludesAdditionalErrorPageTextInProcessStartupFailure_CorrectString() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.TransformArguments((a, _) => $"{a} EarlyReturn"); deploymentParameters.EnvironmentVariables["ANCM_ADDITIONAL_ERROR_PAGE_LINK"] = "http://example"; diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EventLogTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EventLogTests.cs index 168e7bc642..a138cd659a 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EventLogTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/EventLogTests.cs @@ -11,18 +11,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class EventLogTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public EventLogTests(PublishedSitesFixture fixture) + public EventLogTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] public async Task CheckStartupEventLogMessage() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); - + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await DeployAsync(deploymentParameters); await deploymentResult.AssertStarts(); @@ -34,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckShutdownEventLogMessage() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await DeployAsync(deploymentParameters); await deploymentResult.AssertStarts(); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/FrebTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/FrebTests.cs index 5557908acd..b94baa4baa 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/FrebTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/FrebTests.cs @@ -19,10 +19,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class FrebTests : LogFileTestBase { - private readonly PublishedSitesFixture _fixture; - public FrebTests(PublishedSitesFixture fixture) + public FrebTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static IList FrebChecks() @@ -54,7 +52,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.FailedRequestTracingModule)] public async Task FrebIncludesHResultFailures() { - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); parameters.TransformArguments((args, _) => string.Empty); var result = await SetupFrebApp(parameters); @@ -104,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task SetupFrebApp(IISDeploymentParameters parameters = null) { - parameters = parameters ?? _fixture.GetBaseDeploymentParameters(); + parameters = parameters ?? Fixture.GetBaseDeploymentParameters(); parameters.EnableFreb("Verbose", _logFolderPath); Directory.CreateDirectory(_logFolderPath); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/LogPipeTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/LogPipeTests.cs index 47fd6fa425..926e81ad45 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/LogPipeTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/LogPipeTests.cs @@ -14,11 +14,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class LogPipeTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public LogPipeTests(PublishedSitesFixture fixture) + public LogPipeTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalTheory] @@ -26,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("ConsoleWrite")] public async Task CheckStdoutLoggingToPipe_DoesNotCrashProcess(string path) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await DeployAsync(deploymentParameters); await Helpers.AssertStarts(deploymentResult, path); @@ -44,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("ConsoleWriteStartServer")] public async Task CheckStdoutLoggingToPipeWithFirstWrite(string path) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var firstWriteString = "TEST MESSAGE"; @@ -67,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task CheckUnicodePipe() { var path = "CheckConsoleFunctions"; - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} {path}"); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ShutdownTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ShutdownTests.cs index 5515b5ef68..d4e9c9f7cb 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ShutdownTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/ShutdownTests.cs @@ -14,17 +14,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class ShutdownTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public ShutdownTests(PublishedSitesFixture fixture) + public ShutdownTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] public async Task ShutdownTimeoutIsApplied() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} HangOnStop"); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("shutdownTimeLimit", "1")); @@ -47,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { // Canceled token doesn't affect shutdown, in-proc doesn't handle ungraceful shutdown // IIS's ShutdownTimeLimit will handle that. - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await DeployAsync(parameters); try { diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs index 6d544cf8cd..bd468820a2 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs @@ -13,11 +13,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class StartupExceptionTests : LogFileTestBase { - private readonly PublishedSitesFixture _fixture; - - public StartupExceptionTests(PublishedSitesFixture fixture) + public StartupExceptionTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalTheory] @@ -27,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("CheckOversizedStdOutWrites")] public async Task CheckStdoutWithLargeWrites_TestSink(string mode) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} {mode}"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -44,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("CheckOversizedStdOutWrites")] public async Task CheckStdoutWithLargeWrites_LogFile(string mode) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} {mode}"); deploymentParameters.EnableLogging(_logFolderPath); @@ -62,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckValidConsoleFunctions() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} CheckConsoleFunctions"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -84,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task Gets500_30_ErrorPage() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} EarlyReturn"); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs index 9803dfeed9..b4400ffd2c 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; @@ -22,11 +21,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class StartupTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public StartupTests(PublishedSitesFixture fixture) + public StartupTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } private readonly string _dotnetLocation = DotNetCommands.GetDotNetExecutable(RuntimeArchitecture.x64); @@ -36,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task ExpandEnvironmentVariableInWebConfig() { // Point to dotnet installed in user profile. - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.EnvironmentVariables["DotnetPath"] = _dotnetLocation; deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", "%DotnetPath%")); await StartAsync(deploymentParameters); @@ -50,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData("dotnet.zip", "", @"Process path 'dotnet.zip' doesn't have '.exe' extension.")] public async Task InvalidProcessPath_ExpectServerError(string path, string arguments, string subError) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", path)); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("arguments", arguments)); @@ -70,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task StartsWithDotnetLocationWithoutExe() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var dotnetLocationWithoutExtension = _dotnetLocation.Substring(0, _dotnetLocation.LastIndexOf(".")); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", dotnetLocationWithoutExtension)); @@ -81,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task StartsWithDotnetLocationUppercase() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); var dotnetLocationWithoutExtension = _dotnetLocation.Substring(0, _dotnetLocation.LastIndexOf(".")).ToUpperInvariant(); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", dotnetLocationWithoutExtension)); @@ -95,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task StartsWithDotnetOnThePath(string path) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.EnvironmentVariables["PATH"] = Path.GetDirectoryName(_dotnetLocation); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", path)); @@ -117,7 +113,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task StartsWithDotnetInstallLocation(RuntimeArchitecture runtimeArchitecture) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.RuntimeArchitecture = runtimeArchitecture; // IIS doesn't allow empty PATH @@ -149,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task DoesNotStartIfDisabled() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); using (new TestRegistryKey( Registry.LocalMachine, @@ -181,7 +177,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task HelloWorld(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); await StartAsync(deploymentParameters); } @@ -189,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task StartsWithPortableAndBootstraperExe() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformPath((path, root) => "InProcessWebSite.exe"); deploymentParameters.TransformArguments((arguments, root) => ""); @@ -209,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task DetectsOverriddenServer() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} OverriddenServer"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -226,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task LogsStartupExceptionExitError() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} Throw"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -244,7 +240,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task LogsUnexpectedThreadExitError() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} EarlyReturn"); var deploymentResult = await DeployAsync(deploymentParameters); @@ -261,7 +257,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task RemoveHostfxrFromApp_InProcessHostfxrAPIAbsent() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.ApplicationType = ApplicationType.Standalone; var deploymentResult = await DeployAsync(deploymentParameters); @@ -278,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresNewShim] public async Task RemoveHostfxrFromApp_InProcessHostfxrLoadFailure() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.ApplicationType = ApplicationType.Standalone; var deploymentResult = await DeployAsync(deploymentParameters); @@ -292,7 +288,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task TargedDifferenceSharedFramework_FailedToFindNativeDependencies() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); var deploymentResult = await DeployAsync(deploymentParameters); Helpers.ModifyFrameworkVersionInRuntimeConfig(deploymentResult); @@ -304,7 +300,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task RemoveInProcessReference_FailedToFindRequestHandler() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.ApplicationType = ApplicationType.Standalone; var deploymentResult = await DeployAsync(deploymentParameters); @@ -325,7 +321,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact(Skip = "https://github.com/aspnet/AspNetCore-Internal/issues/1772")] public async Task StartupTimeoutIsApplied() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} Hang"); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("startupTimeLimit", "1")); @@ -345,7 +341,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckInvalidHostingModelParameter() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("hostingModel", "bogus")); var deploymentResult = await DeployAsync(deploymentParameters); @@ -369,7 +365,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task ReportsWebConfigAuthoringErrors(string scenario) { var (expectedError, action) = InvalidConfigTransformations[scenario]; - var iisDeploymentParameters = _fixture.GetBaseDeploymentParameters(); + var iisDeploymentParameters = Fixture.GetBaseDeploymentParameters(); iisDeploymentParameters.WebConfigActionList.Add((element, _) => action(element)); var deploymentResult = await DeployAsync(iisDeploymentParameters); var result = await deploymentResult.HttpClient.GetAsync("/HelloWorld"); @@ -414,7 +410,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task StartsWithWebConfigVariationsPortable(string scenario) { var action = PortableConfigTransformations[scenario]; - var iisDeploymentParameters = _fixture.GetBaseDeploymentParameters(); + var iisDeploymentParameters = Fixture.GetBaseDeploymentParameters(); var expectedArguments = action(iisDeploymentParameters); var result = await DeployAsync(iisDeploymentParameters); Assert.Equal(expectedArguments, await result.HttpClient.GetStringAsync("/CommandLineArgs")); @@ -478,7 +474,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task StartsWithWebConfigVariationsStandalone(string scenario) { var action = StandaloneConfigTransformations[scenario]; - var iisDeploymentParameters = _fixture.GetBaseDeploymentParameters(); + var iisDeploymentParameters = Fixture.GetBaseDeploymentParameters(); iisDeploymentParameters.ApplicationType = ApplicationType.Standalone; var expectedArguments = action(iisDeploymentParameters); var result = await DeployAsync(iisDeploymentParameters); @@ -513,7 +509,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresNewHandler] public async Task SetCurrentDirectoryHandlerSettingWorks() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.HandlerSettings["SetCurrentDirectory"] = "false"; var deploymentResult = await DeployAsync(deploymentParameters); @@ -530,7 +526,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task StartupIsSuspendedWhenEventIsUsed() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.ApplicationType = ApplicationType.Standalone; deploymentParameters.EnvironmentVariables["ASPNETCORE_STARTUP_SUSPEND_EVENT"] = "ANCM_TestEvent"; diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs index f4f9b53b00..9ea84650d7 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs @@ -15,11 +15,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class LoggingTests : LogFileTestBase { - private readonly PublishedSitesFixture _fixture; - - public LoggingTests(PublishedSitesFixture fixture) + public LoggingTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -44,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task CheckStdoutToFile(TestVariant variant, string path) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.EnableLogging(_logFolderPath); var deploymentResult = await DeployAsync(deploymentParameters); @@ -63,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task InvalidFilePathForLogs_ServerStillRuns(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true")); @@ -87,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [RequiresNewShim] public async Task StartupMessagesAreLoggedIntoDebugLogFile(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.HandlerSettings["debugLevel"] = "file"; deploymentParameters.HandlerSettings["debugFile"] = "subdirectory\\debug.txt"; @@ -102,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task StartupMessagesAreLoggedIntoDefaultDebugLogFile(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.HandlerSettings["debugLevel"] = "file"; var deploymentResult = await DeployAsync(deploymentParameters); @@ -117,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task StartupMessagesAreLoggedIntoDefaultDebugLogFileWhenEnabledWithEnvVar(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.EnvironmentVariables["ASPNETCORE_MODULE_DEBUG"] = "file"; // Add empty debugFile handler setting to prevent IIS deployer from overriding debug settings deploymentParameters.HandlerSettings["debugFile"] = ""; @@ -138,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests try { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.EnvironmentVariables["ASPNETCORE_MODULE_DEBUG_FILE"] = firstTempFile; deploymentParameters.AddDebugLogToWebConfig(secondTempFile); @@ -165,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task DebugLogsAreWrittenToEventLog(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.HandlerSettings["debugLevel"] = "file,eventlog"; var deploymentResult = await StartAsync(deploymentParameters); StopServer(); @@ -178,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { var path = "CheckConsoleFunctions"; - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite, variant.HostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite, variant.HostingModel); deploymentParameters.TransformArguments((a, _) => $"{a} {path}"); // For standalone this will need to remove space var logFolderPath = _logFolderPath + "\\彡⾔"; @@ -209,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task OnlyOneFileCreatedWithProcessStartTime(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.EnableLogging(_logFolderPath); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/MultiApplicationTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/MultiApplicationTests.cs index f1f0bf163a..90bbcb4291 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/MultiApplicationTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/MultiApplicationTests.cs @@ -18,20 +18,17 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class MultiApplicationTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - private PublishedApplication _publishedApplication; private PublishedApplication _rootApplication; - public MultiApplicationTests(PublishedSitesFixture fixture) + public MultiApplicationTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] public async Task RunsTwoOutOfProcessApps() { - var parameters = _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + var parameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); parameters.ServerConfigActionList.Add(DuplicateApplication); var result = await DeployAsync(parameters); var id1 = await result.HttpClient.GetStringAsync("/app1/ProcessId"); @@ -42,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task FailsAndLogsWhenRunningTwoInProcessApps() { - var parameters = _fixture.GetBaseDeploymentParameters(HostingModel.InProcess); + var parameters = Fixture.GetBaseDeploymentParameters(HostingModel.InProcess); parameters.ServerConfigActionList.Add(DuplicateApplication); var result = await DeployAsync(parameters); @@ -59,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [InlineData(HostingModel.InProcess)] public async Task FailsAndLogsEventLogForMixedHostingModel(HostingModel firstApp) { - var parameters = _fixture.GetBaseDeploymentParameters(firstApp); + var parameters = Fixture.GetBaseDeploymentParameters(firstApp); parameters.ServerConfigActionList.Add(DuplicateApplication); var result = await DeployAsync(parameters); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs index 66482eec43..9991f22150 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs @@ -23,11 +23,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private static readonly Random _random = new Random(); - private readonly PublishedSitesFixture _fixture; - - public AspNetCorePortTests(PublishedSitesFixture fixture) + public AspNetCorePortTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -45,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task EnvVarInWebConfig_Valid(TestVariant variant) { // Must publish to set env vars in web.config - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); var port = GetUnusedRandomPort(); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port.ToString(); @@ -61,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task EnvVarInWebConfig_Empty(TestVariant variant) { // Must publish to set env vars in web.config - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = string.Empty; var deploymentResult = await DeployAsync(deploymentParameters); @@ -77,7 +74,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public async Task EnvVarInWebConfig_Invalid(TestVariant variant, string port) { // Must publish to set env vars in web.config - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port; var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/GlobalVersionTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/GlobalVersionTests.cs index 8b97cd2cb0..e4cdcc1c07 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/GlobalVersionTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/GlobalVersionTests.cs @@ -18,11 +18,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class GlobalVersionTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public GlobalVersionTests(PublishedSitesFixture fixture) + public GlobalVersionTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } private const string _handlerVersion20 = "2.0.0"; @@ -184,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private IISDeploymentParameters GetGlobalVersionBaseDeploymentParameters() { - return _fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + return Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); } private void CopyDirectory(string from, string to) diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs index 8166e52acd..ab8a518944 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs @@ -17,11 +17,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class HelloWorldTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public HelloWorldTests(PublishedSitesFixture fixture) + public HelloWorldTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -33,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task HelloWorld(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.ServerConfigActionList.Add( (element, _) => { element diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISFunctionalTestBase.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISFunctionalTestBase.cs index a20a5e2e0e..79766f68ca 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISFunctionalTestBase.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISFunctionalTestBase.cs @@ -1,15 +1,84 @@ // 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.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; +using Microsoft.Extensions.Logging; +using Xunit; using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities { public class IISFunctionalTestBase : FunctionalTestsBase { - public IISFunctionalTestBase(ITestOutputHelper output = null) : base(output) + protected static readonly TimeSpan RetryDelay = TimeSpan.FromMilliseconds(100); + protected PublishedSitesFixture Fixture { get; set; } + + public IISFunctionalTestBase(PublishedSitesFixture fixture, ITestOutputHelper output = null) : base(output) { + Fixture = fixture; + } + + public async Task DeployApp(HostingModel hostingModel = HostingModel.InProcess) + { + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel: hostingModel); + + return await DeployAsync(deploymentParameters); + } + + public void AddAppOffline(string appPath, string content = "The app is offline.") + { + File.WriteAllText(Path.Combine(appPath, "app_offline.htm"), content); + } + + public void RemoveAppOffline(string appPath) + { + RetryHelper.RetryOperation( + () => File.Delete(Path.Combine(appPath, "app_offline.htm")), + e => Logger.LogError($"Failed to remove app_offline : {e.Message}"), + retryCount: 3, + retryDelayMilliseconds: RetryDelay.Milliseconds); + } + + public async Task AssertAppOffline(IISDeploymentResult deploymentResult, string expectedResponse = "The app is offline.") + { + var response = await deploymentResult.HttpClient.RetryRequestAsync("HelloWorld", r => r.StatusCode == HttpStatusCode.ServiceUnavailable); + Assert.Equal(expectedResponse, await response.Content.ReadAsStringAsync()); + } + + public async Task AssertStarts(HostingModel hostingModel) + { + var deploymentResult = await DeployApp(hostingModel); + + await AssertRunning(deploymentResult); + + return deploymentResult; + } + + public static async Task AssertRunning(IISDeploymentResult deploymentResult) + { + var response = await deploymentResult.HttpClient.RetryRequestAsync("HelloWorld", r => r.IsSuccessStatusCode); + var responseText = await response.Content.ReadAsStringAsync(); + Assert.Equal("Hello World", responseText); + } + + public void DeletePublishOutput(IISDeploymentResult deploymentResult) + { + foreach (var file in Directory.GetFiles(deploymentResult.ContentRoot, "*", SearchOption.AllDirectories)) + { + // Out of process module dll is allowed to be locked + var name = Path.GetFileName(file); + if (name == "aspnetcore.dll" || name == "aspnetcorev2.dll" || name == "aspnetcorev2_outofprocess.dll") + { + continue; + } + File.Delete(file); + } } } } diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/LogFileTestBase.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/LogFileTestBase.cs index 17885f3547..774b74eb15 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/LogFileTestBase.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/LogFileTestBase.cs @@ -13,10 +13,11 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities { protected string _logFolderPath; - public LogFileTestBase(ITestOutputHelper output = null) : base(output) + public LogFileTestBase(PublishedSitesFixture fixture, ITestOutputHelper output = null) : base(fixture, output) { _logFolderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); } + public override void Dispose() { base.Dispose(); diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/WindowsAuthTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/WindowsAuthTests.cs index 1a2dd11d55..5037436499 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/WindowsAuthTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/WindowsAuthTests.cs @@ -15,11 +15,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class WindowsAuthTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public WindowsAuthTests(PublishedSitesFixture fixture) + public WindowsAuthTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -33,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task WindowsAuthTest(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.SetAnonymousAuth(enabled: false); deploymentParameters.SetWindowsAuth(); diff --git a/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/Inprocess/StdOutRedirectionTests.cs b/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/Inprocess/StdOutRedirectionTests.cs index 80b7881d2e..a8a47e7c68 100644 --- a/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/Inprocess/StdOutRedirectionTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/Inprocess/StdOutRedirectionTests.cs @@ -17,18 +17,15 @@ namespace IIS.FunctionalTests.Inprocess [Collection(PublishedSitesCollection.Name)] public class StdOutRedirectionTests : LogFileTestBase { - private readonly PublishedSitesFixture _fixture; - - public StdOutRedirectionTests(PublishedSitesFixture fixture) + public StdOutRedirectionTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] [RequiresNewShim] public async Task FrameworkNotFoundExceptionLogged_Pipe() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); var deploymentResult = await DeployAsync(deploymentParameters); @@ -48,7 +45,7 @@ namespace IIS.FunctionalTests.Inprocess public async Task FrameworkNotFoundExceptionLogged_File() { var deploymentParameters = - _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.EnableLogging(_logFolderPath); @@ -73,7 +70,7 @@ namespace IIS.FunctionalTests.Inprocess public async Task EnableCoreHostTraceLogging_TwoLogFilesCreated() { var deploymentParameters = - _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.TransformArguments((a, _) => $"{a} CheckLargeStdOutWrites"); deploymentParameters.EnvironmentVariables["COREHOST_TRACE"] = "1"; @@ -102,7 +99,7 @@ namespace IIS.FunctionalTests.Inprocess [InlineData("CheckOversizedStdOutWrites")] public async Task EnableCoreHostTraceLogging_PipeCaptureNativeLogs(string path) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.EnvironmentVariables["COREHOST_TRACE"] = "1"; deploymentParameters.TransformArguments((a, _) => $"{a} {path}"); @@ -127,7 +124,7 @@ namespace IIS.FunctionalTests.Inprocess public async Task EnableCoreHostTraceLogging_FileCaptureNativeLogs(string path) { var deploymentParameters = - _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite); + Fixture.GetBaseDeploymentParameters(Fixture.InProcessTestSite); deploymentParameters.EnvironmentVariables["COREHOST_TRACE"] = "1"; deploymentParameters.TransformArguments((a, _) => $"{a} {path}"); diff --git a/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs b/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs index 6b777aae57..12b853799d 100644 --- a/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs @@ -19,11 +19,8 @@ namespace IIS.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class ApplicationInitializationTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public ApplicationInitializationTests(PublishedSitesFixture fixture) + public ApplicationInitializationTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalTheory] @@ -35,7 +32,7 @@ namespace IIS.FunctionalTests // This test often hits a memory leak in warmup.dll module, it has been reported to IIS team using (AppVerifier.Disable(DeployerSelector.ServerType, 0x900)) { - var baseDeploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var baseDeploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); baseDeploymentParameters.TransformArguments( (args, contentRoot) => $"{args} CreateFile \"{Path.Combine(contentRoot, "Started.txt")}\""); EnablePreload(baseDeploymentParameters); @@ -58,7 +55,7 @@ namespace IIS.FunctionalTests // This test often hits a memory leak in warmup.dll module, it has been reported to IIS team using (AppVerifier.Disable(DeployerSelector.ServerType, 0x900)) { - var baseDeploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var baseDeploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); EnablePreload(baseDeploymentParameters); baseDeploymentParameters.ServerConfigActionList.Add( diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AppOfflineIISExpressTests.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AppOfflineIISExpressTests.cs new file mode 100644 index 0000000000..5b7af505cd --- /dev/null +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AppOfflineIISExpressTests.cs @@ -0,0 +1,67 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; +using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Testing.xunit; +using Xunit; + +namespace IISExpress.FunctionalTests.Inprocess +{ + [Collection(PublishedSitesCollection.Name)] + public class AppOfflineIISExpressTests : IISFunctionalTestBase + { + public AppOfflineIISExpressTests(PublishedSitesFixture fixture) : base(fixture) + { + } + + [ConditionalFact] + public async Task AppOfflineDroppedWhileSiteStarting_SiteShutsDown_InProcess() + { + // This test often hits a race between debug logging and stdout redirection closing the handle + // we are fine having this race + using (AppVerifier.Disable(DeployerSelector.ServerType, 0x300)) + { + var deploymentResult = await DeployApp(HostingModel.InProcess); + + for (int i = 0; i < 10; i++) + { + // send first request and add app_offline while app is starting + var runningTask = AssertAppOffline(deploymentResult); + + // This test tries to hit a race where we drop app_offline file while + // in process application is starting, application start takes at least 400ms + // so we back off for 100ms to allow request to reach request handler + // Test itself is racy and can result in two scenarios + // 1. ANCM detects app_offline before it starts the request - if AssertAppOffline succeeds we've hit it + // 2. Intended scenario where app starts and then shuts down + // In first case we remove app_offline and try again + await Task.Delay(RetryDelay); + + AddAppOffline(deploymentResult.ContentRoot); + + try + { + await runningTask.DefaultTimeout(); + + // if AssertAppOffline succeeded ANCM have picked up app_offline before starting the app + // try again + RemoveAppOffline(deploymentResult.ContentRoot); + } + catch + { + // For IISExpress, we need to catch the exception because IISExpress will not restart a process if it crashed. + // RemoveAppOffline will fail due to a bad request exception as the server is down. + Assert.Contains(TestSink.Writes, context => context.Message.Contains("Drained all requests, notifying managed.")); + deploymentResult.AssertWorkerProcessStop(); + return; + } + } + + Assert.True(false); + } + } + } +} diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs index 2c4eb88fed..95fed4d462 100644 --- a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs @@ -14,18 +14,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class AuthenticationTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public AuthenticationTests(PublishedSitesFixture fixture) + public AuthenticationTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] [RequiresIIS(IISCapability.WindowsAuthentication)] public async Task Authentication_InProcess() { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(); deploymentParameters.SetWindowsAuth(); var deploymentResult = await DeployAsync(deploymentParameters); diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/IISExpressShutdownTests.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/IISExpressShutdownTests.cs index 4edad3580f..912aecf293 100644 --- a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/IISExpressShutdownTests.cs +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/IISExpressShutdownTests.cs @@ -17,17 +17,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class IISExpressShutdownTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - public IISExpressShutdownTests(PublishedSitesFixture fixture) + public IISExpressShutdownTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] public async Task ServerShutsDownWhenMainExits() { - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await DeployAsync(parameters); try { @@ -45,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task ServerShutsDownWhenMainExitsStress() { - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); var deploymentResult = await StartAsync(parameters); var load = Helpers.StressLoad(deploymentResult.HttpClient, "/HelloWorld", response => { @@ -69,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task GracefulShutdown_DoesNotCrashProcess() { - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); var result = await DeployAsync(parameters); var response = await result.HttpClient.GetAsync("/HelloWorld"); @@ -80,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task ForcefulShutdown_DoesCrashProcess() { - var parameters = _fixture.GetBaseDeploymentParameters(); + var parameters = Fixture.GetBaseDeploymentParameters(); var result = await DeployAsync(parameters); var response = await result.HttpClient.GetAsync("/HelloWorld"); diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/MultipleAppTests.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/MultipleAppTests.cs index 091d4a7918..9b9a7e8dba 100644 --- a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/MultipleAppTests.cs +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/MultipleAppTests.cs @@ -16,11 +16,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [Collection(PublishedSitesCollection.Name)] public class MultipleAppTests : IISFunctionalTestBase { - private readonly PublishedSitesFixture _fixture; - - public MultipleAppTests(PublishedSitesFixture fixture) + public MultipleAppTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] @@ -35,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests // Deploy all apps for (var i = 0; i < numApps; i++) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel: IntegrationTesting.HostingModel.OutOfProcess); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel: IntegrationTesting.HostingModel.OutOfProcess); var deployer = CreateDeployer(deploymentParameters); deployers.Add(deployer); deploymentResults.Add(await deployer.DeployAsync()); diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs index 5a9df13799..d4b94ea59d 100644 --- a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs @@ -21,11 +21,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests // TODO either enable windows auth on our CI or use containers to test this // behavior - private readonly PublishedSitesFixture _fixture; - - public NtlmAuthenticationTests(PublishedSitesFixture fixture) + public NtlmAuthenticationTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } public static TestMatrix TestVariants @@ -37,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task NtlmAuthentication(TestVariant variant) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(variant); deploymentParameters.ApplicationBaseUriHint = $"https://localhost:0/"; deploymentParameters.SetWindowsAuth(enabled: true); diff --git a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs index d1278997c8..7c036c1815 100644 --- a/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs +++ b/src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs @@ -16,11 +16,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public class UpgradeFeatureDetectionTests : IISFunctionalTestBase { private readonly string _isWebsocketsSupported = Environment.OSVersion.Version >= new Version(6, 2) ? "Enabled" : "Disabled"; - private readonly PublishedSitesFixture _fixture; - public UpgradeFeatureDetectionTests(PublishedSitesFixture fixture) + public UpgradeFeatureDetectionTests(PublishedSitesFixture fixture) : base(fixture) { - _fixture = fixture; } [ConditionalFact] @@ -58,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests private async Task UpgradeFeatureDetectionDeployer(bool disableWebSocket, string expected, HostingModel hostingModel) { - var deploymentParameters = _fixture.GetBaseDeploymentParameters(hostingModel); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel); if (disableWebSocket) {