From 24e2e5ad52d97ac4c83037e8ea26d72b31133bb6 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 15 Oct 2018 11:44:51 -0700 Subject: [PATCH] Port startup tests to IIS (#1513) --- .../IISDeployer.cs | 24 ++++++++++++------- .../Utilities/AppVerifier.cs | 2 +- .../Utilities/EventLogHelpers.cs | 2 +- .../Utilities/Helpers.cs | 8 ++++++- .../Inprocess}/StartupTests.cs | 7 ++++++ 5 files changed, 32 insertions(+), 11 deletions(-) rename test/{IISExpress.FunctionalTests/InProcess => IIS.FunctionalTests/Inprocess}/StartupTests.cs (98%) diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs index a2c3360cf4..4f2e525e72 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs @@ -119,12 +119,18 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS key: "hostingModel", value: DeploymentParameters.HostingModel.ToString()); - if (DeploymentParameters.ApplicationType == ApplicationType.Portable) - { - yield return WebConfigHelpers.AddOrModifyAspNetCoreSection( - "processPath", - DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture)); - } + yield return (element, _) => { + var aspNetCore = element + .Descendants("system.webServer") + .Single() + .GetOrAdd("aspNetCore"); + + // Expand path to dotnet because IIS process would not inherit PATH variable + if (aspNetCore.Attribute("processPath")?.Value.StartsWith("dotnet") == true) + { + aspNetCore.SetAttributeValue("processPath", DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture)); + } + }; yield return WebConfigHelpers.AddOrModifyHandlerSection( key: "modules", @@ -399,8 +405,10 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS redirectionSection.Attributes["enabled"].Value = false; serverManager.CommitChanges(); - - Directory.Delete(_configPath, true); + if (Directory.Exists(_configPath)) + { + Directory.Delete(_configPath, true); + } }); } } diff --git a/test/Common.FunctionalTests/Utilities/AppVerifier.cs b/test/Common.FunctionalTests/Utilities/AppVerifier.cs index ab059d789d..7984193e29 100644 --- a/test/Common.FunctionalTests/Utilities/AppVerifier.cs +++ b/test/Common.FunctionalTests/Utilities/AppVerifier.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting if (process.ExitCode != 0) { - throw new InvalidOperationException($"Exit code {process.ExitCode} when running {fileName} {arguments}. Stdout: {process.StandardOutput.ReadToEnd()}"); + throw new InvalidOperationException($"Exit code {process.ExitCode} when running {fileName} {arguments}. Stdout: {process.StandardOutput.ReadToEnd()} Stderr: {process.StandardError.ReadToEnd()}"); } } diff --git a/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs index cf977b76f4..78c77fd2ca 100644 --- a/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs +++ b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public static string InProcessFailedToStop(IISDeploymentResult deploymentResult, string reason) { - return "Failed to gracefully shutdown application 'MACHINE/WEBROOT/APPHOST/HTTPTESTSITE'."; + return "Failed to gracefully shutdown application 'MACHINE/WEBROOT/APPHOST/.*?'."; } public static string InProcessThreadException(IISDeploymentResult deploymentResult, string reason) diff --git a/test/Common.FunctionalTests/Utilities/Helpers.cs b/test/Common.FunctionalTests/Utilities/Helpers.cs index f3cf2ba70d..4918a12781 100644 --- a/test/Common.FunctionalTests/Utilities/Helpers.cs +++ b/test/Common.FunctionalTests/Utilities/Helpers.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests @@ -203,5 +202,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var output = JsonConvert.SerializeObject(depsFileContent); File.WriteAllText(path, output); } + + public static void AllowNoLogs(this IISDeploymentResult deploymentResult) + { + File.AppendAllText( + Path.Combine(deploymentResult.DeploymentParameters.PublishedApplicationRootPath, "aspnetcore-debug.log"), + "Running test allowed log file to be empty." + Environment.NewLine); + } } } diff --git a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs b/test/IIS.FunctionalTests/Inprocess/StartupTests.cs similarity index 98% rename from test/IISExpress.FunctionalTests/InProcess/StartupTests.cs rename to test/IIS.FunctionalTests/Inprocess/StartupTests.cs index 037ab8eb2e..880a260582 100644 --- a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs +++ b/test/IIS.FunctionalTests/Inprocess/StartupTests.cs @@ -120,9 +120,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests } [ConditionalFact] + [RequiresIIS(IISCapability.PoolEnvironmentVariables)] public async Task StartsWithPortableAndBootstraperExe() { var deploymentParameters = _fixture.GetBaseDeploymentParameters(_fixture.InProcessTestSite, publish: true); + // We need the right dotnet on the path in IIS + deploymentParameters.EnvironmentVariables["PATH"] = Path.GetDirectoryName(DotNetCommands.GetDotNetExecutable(deploymentParameters.RuntimeArchitecture)); + // rest publisher as it doesn't support additional parameters deploymentParameters.ApplicationPublisher = null; // ReferenceTestTasks is workaround for https://github.com/dotnet/sdk/issues/2482 @@ -302,6 +306,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var result = await deploymentResult.HttpClient.GetAsync("/HelloWorld"); Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode); + // Config load errors might not allow us to initialize log file + deploymentResult.AllowNoLogs(); + StopServer(); EventLogHelpers.VerifyEventLogEvents(deploymentResult,