From 0131015b4327787d2d9f556ca1d7694581c733ec Mon Sep 17 00:00:00 2001 From: Chris R Date: Sat, 26 Sep 2015 22:29:08 -0700 Subject: [PATCH] Update server test infrastructure, remove Helios concepts. --- .../Common/DeploymentParameters.cs | 3 ++ .../Common/RetryHelper.cs | 18 +++---- .../Common/ServerType.cs | 1 - .../Deployers/ApplicationDeployer.cs | 24 ++++------ .../Deployers/ApplicationDeployerFactory.cs | 1 - .../Deployers/IISDeployer.cs | 45 ++++------------- .../Deployers/IISExpressDeployer.cs | 48 ++----------------- .../Deployers/SelfHostDeployer.cs | 8 +++- ...fIISNativeVariationsNotEnabledAttribute.cs | 33 ------------- 9 files changed, 42 insertions(+), 139 deletions(-) delete mode 100644 src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs diff --git a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs index 86d29d9b2b..842e65b70f 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/DeploymentParameters.cs @@ -89,6 +89,9 @@ namespace Microsoft.AspNet.Server.Testing /// public Action UserAdditionalCleanup { get; set; } + // Which command in the test project to run. + public string Command { get; set; } + public override string ToString() { return string.Format( diff --git a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs index ae2cedd6e7..48b47b4706 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/RetryHelper.cs @@ -27,14 +27,14 @@ namespace Microsoft.AspNet.Server.Testing { for (int retry = 0; retry < retryCount; retry++) { + if (cancellationToken.IsCancellationRequested) + { + logger.LogInformation("Failed to connect, retry canceled."); + throw new OperationCanceledException("Failed to connect, retry canceled.", cancellationToken); + } + try { - if (cancellationToken.IsCancellationRequested) - { - logger.LogInformation("Stopping retry as cancellation token is triggered."); - break; - } - logger.LogWarning("Retry count {retryCount}..", retry + 1); var response = await retryBlock(); @@ -45,12 +45,13 @@ namespace Microsoft.AspNet.Server.Testing continue; } - return response; //Went through successfully + return response; // Went through successfully } catch (Exception exception) { if (retry == retryCount - 1) { + logger.LogError("Failed to connect, retry limit exceeded.", exception); throw; } else @@ -68,7 +69,8 @@ namespace Microsoft.AspNet.Server.Testing } } - return null; + logger.LogInformation("Failed to connect, retry limit exceeded."); + throw new OperationCanceledException("Failed to connect, retry limit exceeded."); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs index 3d17cb23bd..eca333942e 100644 --- a/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs +++ b/src/Microsoft.AspNet.Server.Testing/Common/ServerType.cs @@ -7,7 +7,6 @@ namespace Microsoft.AspNet.Server.Testing { IISExpress, IIS, - IISNativeModule, WebListener, Kestrel } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs index 6dd076e1a1..19fe88337b 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployer.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Testing { var runtimePath = Process.GetCurrentProcess().MainModule.FileName; Logger.LogInformation(string.Empty); - Logger.LogInformation("Current runtime path is : {0}", runtimePath); + Logger.LogInformation($"Current runtime path is : {runtimePath}"); var replaceStr = new StringBuilder(). Append("dnx"). @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Server.Testing ChosenRuntimeName = runtimeDirectoryInfo.Parent.Name; Logger.LogInformation(string.Empty); - Logger.LogInformation("Changing to use runtime : {runtimeName}", ChosenRuntimeName); + Logger.LogInformation($"Changing to use runtime : {ChosenRuntimeName}"); return ChosenRuntimeName; } @@ -70,16 +70,13 @@ namespace Microsoft.AspNet.Server.Testing { DeploymentParameters.PublishedApplicationRootPath = Path.Combine(publishRoot ?? Path.GetTempPath(), Guid.NewGuid().ToString()); - var parameters = - string.Format( - "publish {0} -o {1} --runtime {2} {3}", - DeploymentParameters.ApplicationPath, - DeploymentParameters.PublishedApplicationRootPath, - DeploymentParameters.DnxRuntime, - DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty); + var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty; + var command = DeploymentParameters.Command ?? "web"; + var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}" + + $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}"; var dnuPath = Path.Combine(ChosenRuntimePath, "dnu.cmd"); - Logger.LogInformation("Executing command {dnu} {args}", dnuPath, parameters); + Logger.LogInformation($"Executing command {dnuPath} {parameters}"); var startInfo = new ProcessStartInfo { @@ -106,13 +103,12 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationPath = (DeploymentParameters.ServerType == ServerType.IISExpress || - DeploymentParameters.ServerType == ServerType.IISNativeModule || DeploymentParameters.ServerType == ServerType.IIS) ? Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") : Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); - Logger.LogInformation("dnu publish finished with exit code : {exitCode}", hostProcess.ExitCode); + Logger.LogInformation($"dnu publish finished with exit code : {hostProcess.ExitCode}"); } protected void CleanPublishedOutput() @@ -124,7 +120,7 @@ namespace Microsoft.AspNet.Server.Testing } catch (Exception exception) { - Logger.LogWarning("Failed to delete directory : {error}", exception.Message); + Logger.LogWarning($"Failed to delete directory : {exception.Message}"); } } @@ -225,7 +221,7 @@ namespace Microsoft.AspNet.Server.Testing protected void StartTimer() { - Logger.LogInformation("Deploying {VariationDetails}", DeploymentParameters.ToString()); + Logger.LogInformation($"Deploying {DeploymentParameters.ToString()}"); StopWatch.Start(); } diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs index 6422d3f507..d40a6562c1 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/ApplicationDeployerFactory.cs @@ -40,7 +40,6 @@ namespace Microsoft.AspNet.Server.Testing return new IISExpressDeployer(deploymentParameters, logger); #if DNX451 case ServerType.IIS: - case ServerType.IISNativeModule: return new IISDeployer(deploymentParameters, logger); #endif case ServerType.WebListener: diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs index b7290b9f9c..fe3e046254 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISDeployer.cs @@ -41,14 +41,8 @@ namespace Microsoft.AspNet.Server.Testing // Publish to IIS root\application folder. DnuPublish(publishRoot: _application.WebSiteRootFolder); - // Drop an ini file instead of setting environment variable. - SetAspEnvironmentWithIni(); - - // Setup the IIS Application. - if (DeploymentParameters.ServerType == ServerType.IISNativeModule) - { - TurnRammFarOnNativeModule(); - } + // Drop a json file instead of setting environment variable. + SetAspEnvironmentWithJson(); lock (_syncObject) { @@ -70,30 +64,12 @@ namespace Microsoft.AspNet.Server.Testing }; } - private void SetAspEnvironmentWithIni() + private void SetAspEnvironmentWithJson() { - // Drop a Microsoft.AspNet.Hosting.ini with ASPNET_ENV information. - Logger.LogInformation("Creating Microsoft.AspNet.Hosting.ini file with ASPNET_ENV."); - var iniFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.ini"); - File.WriteAllText(iniFile, string.Format("ASPNET_ENV={0}", DeploymentParameters.EnvironmentName)); - } - - private void TurnRammFarOnNativeModule() - { - Logger.LogInformation("Turning runAllManagedModulesForAllRequests=true in web.config for native module."); - var webConfig = Path.Combine(DeploymentParameters.ApplicationPath, "web.config"); - var configuration = new XmlDocument(); - configuration.LoadXml(File.ReadAllText(webConfig)); - - // https://github.com/aspnet/Helios/issues/77 - var rammfarAttribute = configuration.CreateAttribute("runAllManagedModulesForAllRequests"); - rammfarAttribute.Value = "true"; - var modulesNode = configuration.CreateElement("modules"); - modulesNode.Attributes.Append(rammfarAttribute); - var systemWebServerNode = configuration.CreateElement("system.webServer"); - systemWebServerNode.AppendChild(modulesNode); - configuration.SelectSingleNode("//configuration").AppendChild(systemWebServerNode); - configuration.Save(webConfig); + // Drop a Microsoft.AspNet.Hosting.json with Hosting:Environment information. + Logger.LogInformation("Creating Microsoft.AspNet.Hosting.json file with Hosting:Environment."); + var jsonFile = Path.Combine(DeploymentParameters.ApplicationPath, "Microsoft.AspNet.Hosting.json"); + File.WriteAllText(jsonFile, string.Format("{ \"Hosting:Environment\":\"{0}\" }", DeploymentParameters.EnvironmentName)); } public override void Dispose() @@ -118,8 +94,6 @@ namespace Microsoft.AspNet.Server.Testing private class IISApplication { private const string WebSiteName = "ASPNETTESTRUNS"; - private const string NativeModuleManagedRuntimeVersion = "vCoreFX"; - private const string Dotnet45RuntimeVersion = "v4.0.30319"; private readonly ServerManager _serverManager = new ServerManager(); private readonly DeploymentParameters _deploymentParameters; @@ -176,10 +150,7 @@ namespace Microsoft.AspNet.Server.Testing private ApplicationPool CreateAppPool(string appPoolName) { var applicationPool = _serverManager.ApplicationPools.Add(appPoolName); - applicationPool.ManagedRuntimeVersion = - _deploymentParameters.ServerType == ServerType.IISNativeModule ? - NativeModuleManagedRuntimeVersion : - Dotnet45RuntimeVersion; + applicationPool.ManagedRuntimeVersion = string.Empty; applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86); _logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.", diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs index 5309a59925..bd334652a8 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/IISExpressDeployer.cs @@ -5,8 +5,6 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Server.Testing @@ -30,6 +28,8 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); + // For now we always auto-publish. Otherwise we'll have to write our own local web.config for the HttpPlatformHandler + DeploymentParameters.PublishApplicationBeforeDeployment = true; if (DeploymentParameters.PublishApplicationBeforeDeployment) { DnuPublish(); @@ -57,18 +57,12 @@ namespace Microsoft.AspNet.Server.Testing DeploymentParameters.ApplicationHostConfigTemplateContent = DeploymentParameters.ApplicationHostConfigTemplateContent - .Replace("[ApplicationPhysicalPath]", Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot")) - .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); + .Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath) + .Replace("[PORT]", new Uri(DeploymentParameters.ApplicationBaseUriHint).Port.ToString()); DeploymentParameters.ApplicationHostConfigLocation = Path.GetTempFileName(); - File.WriteAllText(DeploymentParameters.ApplicationHostConfigLocation, - DeploymentParameters.ApplicationHostConfigTemplateContent.Replace("[ApplicationPhysicalPath]", DeploymentParameters.ApplicationPath)); - } - - if (!DeploymentParameters.PublishApplicationBeforeDeployment) - { - CopyAspNetLoader(); + File.WriteAllText(DeploymentParameters.ApplicationHostConfigLocation, DeploymentParameters.ApplicationHostConfigTemplateContent); } var webroot = DeploymentParameters.ApplicationPath; @@ -129,38 +123,6 @@ namespace Microsoft.AspNet.Server.Testing return hostExitTokenSource.Token; } - private void CopyAspNetLoader() - { - var libraryManager = (ILibraryManager)CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(ILibraryManager)); - var interopLibrary = libraryManager.GetLibrary("Microsoft.AspNet.Loader.IIS.Interop"); - - if (interopLibrary == null) - { - throw new Exception( - string.Format("Include Microsoft.AspNet.Server.IIS package in your project.json to deploy in {0}.", - ServerType.IISExpress)); - } - - var aspNetLoaderSrcPath = Path.Combine(interopLibrary.Path, "tools", "AspNet.Loader.dll"); - var aspNetLoaderDestPath = Path.Combine(DeploymentParameters.ApplicationPath, "wwwroot", "bin", "AspNet.Loader.dll"); - - // Create bin directory if it does not exist. - Directory.CreateDirectory(new DirectoryInfo(aspNetLoaderDestPath).Parent.FullName); - - if (!File.Exists(aspNetLoaderDestPath)) - { - try - { - File.Copy(aspNetLoaderSrcPath, aspNetLoaderDestPath); - } - catch (IOException) - { - // Ignore file already exists exception. Sometimes multiple tests might try - // doing the same and one of them wins. - } - } - } - private string GetIISExpressPath() { // Get path to program files diff --git a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs index 685a88e388..cd1293028d 100644 --- a/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNet.Server.Testing/Deployers/SelfHostDeployer.cs @@ -47,9 +47,13 @@ namespace Microsoft.AspNet.Server.Testing private CancellationToken StartSelfHost() { - var commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + var commandName = DeploymentParameters.Command; + if (string.IsNullOrEmpty(commandName)) + { + commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel"; + } var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe"); - var dnxArgs = $"--appbase \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; + var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" Microsoft.Dnx.ApplicationHost {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}"; Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs); var startInfo = new ProcessStartInfo diff --git a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs b/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs deleted file mode 100644 index b3c13646ce..0000000000 --- a/src/Microsoft.AspNet.Server.Testing/xunit/SkipIfIISNativeVariationsNotEnabledAttribute.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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 Microsoft.AspNet.Testing.xunit; - -namespace Microsoft.AspNet.Server.Testing -{ - /// - /// Skip test if IIS native module is not enabled. To enable setup native module - /// and set environment variable IIS_NATIVE_VARIATIONS_ENABLED=true for the test process. - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class SkipIfIISNativeVariationsNotEnabledAttribute : Attribute, ITestCondition - { - public bool IsMet - { - get - { - return Environment.GetEnvironmentVariable("IIS_NATIVE_VARIATIONS_ENABLED") == "true"; - } - } - - public string SkipReason - { - get - { - return "Skipping Native module test since native module variations are not enabled. " + - "To run the test, setup the native module and set the environment variable IIS_NATIVE_VARIATIONS_ENABLED=true."; - } - } - } -} \ No newline at end of file