From cae0d494a95a6e0b01508767fdb399cbe605f5f6 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 15 Apr 2015 21:37:15 -0700 Subject: [PATCH] Moving some logging into the helpers --- .../Common/DeploymentParameters.cs | 12 ++++++ .../Deployers/ApplicationDeployer.cs | 41 +++++++++++++++++-- .../Deployers/IISDeployer.cs | 5 +++ .../Deployers/IISExpressDeployer.cs | 13 ++++-- .../Deployers/MonoDeployer.cs | 5 +++ .../Deployers/SelfHostDeployer.cs | 5 +++ test/E2ETests/NtlmAuthentationTest.cs | 15 ++----- test/E2ETests/OpenIdConnectTests.cs | 15 ++----- test/E2ETests/PublishAndRunTests.cs | 15 ++----- test/E2ETests/SmokeTests.cs | 16 ++------ 10 files changed, 85 insertions(+), 57 deletions(-) diff --git a/test/DeploymentHelpers/Common/DeploymentParameters.cs b/test/DeploymentHelpers/Common/DeploymentParameters.cs index 849a144e72..3718ef0578 100644 --- a/test/DeploymentHelpers/Common/DeploymentParameters.cs +++ b/test/DeploymentHelpers/Common/DeploymentParameters.cs @@ -85,5 +85,17 @@ namespace DeploymentHelpers /// For any application level cleanup to be invoked after performing host cleanup. /// public Action UserAdditionalCleanup { get; set; } + + public override string ToString() + { + return string.Format( + "[Variation] :: ServerType={0}, Runtime={1}, Arch={2}, BaseUrlHint={3}, Publish={4}, NoSource={5}", + ServerType, + RuntimeFlavor, + RuntimeArchitecture, + ApplicationBaseUriHint, + PublishApplicationBeforeDeployment, + PublishWithNoSource); + } } } \ No newline at end of file diff --git a/test/DeploymentHelpers/Deployers/ApplicationDeployer.cs b/test/DeploymentHelpers/Deployers/ApplicationDeployer.cs index a04e3f6124..0212627324 100644 --- a/test/DeploymentHelpers/Deployers/ApplicationDeployer.cs +++ b/test/DeploymentHelpers/Deployers/ApplicationDeployer.cs @@ -21,6 +21,8 @@ namespace DeploymentHelpers protected ILogger Logger { get; private set; } + protected Stopwatch StopWatch { get; private set; } = new Stopwatch(); + public abstract DeploymentResult Deploy(); public ApplicationDeployer( @@ -140,19 +142,38 @@ namespace DeploymentHelpers startInfo.Environment; #endif - environment["ASPNET_ENV"] = DeploymentParameters.EnvironmentName; + SetEnvironmentVariable(environment, "ASPNET_ENV", DeploymentParameters.EnvironmentName); // Work around for https://github.com/aspnet/dnx/issues/1515 if (DeploymentParameters.PublishWithNoSource) { - environment.Remove("DNX_PACKAGES"); + SetEnvironmentVariable(environment, "DNX_PACKAGES", null); } - environment.Remove("DNX_DEFAULT_LIB"); + SetEnvironmentVariable(environment, "DNX_DEFAULT_LIB", null); foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables) { - environment[environmentVariable.Key] = environmentVariable.Value; + SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value); + } + } + +#if DNX451 + protected void SetEnvironmentVariable(System.Collections.Specialized.StringDictionary environment, string name, string value) + { +#elif DNXCORE50 + protected void SetEnvironmentVariable(System.Collections.Generic.IDictionary environment, string name, string value) + { +#endif + if (value == null) + { + Logger.LogInformation("Removing environment variable {name}", name); + environment.Remove(name); + } + else + { + Logger.LogInformation("SET {name}={value}", name, value); + environment[name] = value; } } @@ -184,6 +205,18 @@ namespace DeploymentHelpers } } + protected void StartTimer() + { + Logger.LogInformation("Deploying {VariationDetails}", DeploymentParameters.ToString()); + StopWatch.Start(); + } + + protected void StopTimer() + { + StopWatch.Stop(); + Logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", StopWatch.Elapsed.TotalSeconds); + } + public abstract void Dispose(); } } \ No newline at end of file diff --git a/test/DeploymentHelpers/Deployers/IISDeployer.cs b/test/DeploymentHelpers/Deployers/IISDeployer.cs index fc0e5d1bae..4cd7f91a18 100644 --- a/test/DeploymentHelpers/Deployers/IISDeployer.cs +++ b/test/DeploymentHelpers/Deployers/IISDeployer.cs @@ -24,6 +24,9 @@ namespace DeploymentHelpers public override DeploymentResult Deploy() { + // Start timer + StartTimer(); + // Only supports publish and run on IIS. DeploymentParameters.PublishApplicationBeforeDeployment = true; @@ -93,6 +96,8 @@ namespace DeploymentHelpers CleanPublishedOutput(); InvokeUserApplicationCleanup(); + + StopTimer(); } private class IISApplication diff --git a/test/DeploymentHelpers/Deployers/IISExpressDeployer.cs b/test/DeploymentHelpers/Deployers/IISExpressDeployer.cs index f686cda17a..1e3ba2d89e 100644 --- a/test/DeploymentHelpers/Deployers/IISExpressDeployer.cs +++ b/test/DeploymentHelpers/Deployers/IISExpressDeployer.cs @@ -22,6 +22,9 @@ namespace DeploymentHelpers public override DeploymentResult Deploy() { + // Start timer + StartTimer(); + DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); if (DeploymentParameters.PublishApplicationBeforeDeployment) @@ -91,11 +94,11 @@ namespace DeploymentHelpers // IIS express figures out the DNX from %PATH%. #if DNX451 - startInfo.EnvironmentVariables["PATH"] = ChosenRuntimePath + ";" + startInfo.EnvironmentVariables["PATH"]; - startInfo.EnvironmentVariables["DNX_APPBASE"] = DeploymentParameters.ApplicationPath; + SetEnvironmentVariable(startInfo.EnvironmentVariables, "PATH", ChosenRuntimePath + ";" + startInfo.EnvironmentVariables["PATH"]); + SetEnvironmentVariable(startInfo.EnvironmentVariables, "DNX_APPBASE", DeploymentParameters.ApplicationPath); #elif DNXCORE50 - startInfo.Environment["PATH"] = ChosenRuntimePath + ";" + startInfo.Environment["PATH"]; - startInfo.Environment["DNX_APPBASE"] = DeploymentParameters.ApplicationPath; + SetEnvironmentVariable(startInfo.Environment, "PATH", ChosenRuntimePath + ";" + startInfo.Environment["PATH"]); + SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath); #endif _hostProcess = Process.Start(startInfo); @@ -194,6 +197,8 @@ namespace DeploymentHelpers } InvokeUserApplicationCleanup(); + + StopTimer(); } } } \ No newline at end of file diff --git a/test/DeploymentHelpers/Deployers/MonoDeployer.cs b/test/DeploymentHelpers/Deployers/MonoDeployer.cs index e98fe5c849..7917e86e7e 100644 --- a/test/DeploymentHelpers/Deployers/MonoDeployer.cs +++ b/test/DeploymentHelpers/Deployers/MonoDeployer.cs @@ -21,6 +21,9 @@ namespace DeploymentHelpers public override DeploymentResult Deploy() { + // Start timer + StartTimer(); + var path = Environment.GetEnvironmentVariable("PATH"); var runtimeBin = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries). Where(c => c.Contains("dnx-mono")).FirstOrDefault(); @@ -97,6 +100,8 @@ namespace DeploymentHelpers } InvokeUserApplicationCleanup(); + + StopTimer(); } } } \ No newline at end of file diff --git a/test/DeploymentHelpers/Deployers/SelfHostDeployer.cs b/test/DeploymentHelpers/Deployers/SelfHostDeployer.cs index 6ddc9a1569..2623c4ddff 100644 --- a/test/DeploymentHelpers/Deployers/SelfHostDeployer.cs +++ b/test/DeploymentHelpers/Deployers/SelfHostDeployer.cs @@ -20,6 +20,9 @@ namespace DeploymentHelpers public override DeploymentResult Deploy() { + // Start timer + StartTimer(); + DeploymentParameters.DnxRuntime = PopulateChosenRuntimeInformation(); if (DeploymentParameters.PublishApplicationBeforeDeployment) @@ -81,6 +84,8 @@ namespace DeploymentHelpers } InvokeUserApplicationCleanup(); + + StopTimer(); } } } \ No newline at end of file diff --git a/test/E2ETests/NtlmAuthentationTest.cs b/test/E2ETests/NtlmAuthentationTest.cs index 4bce69f22d..5535d21d79 100644 --- a/test/E2ETests/NtlmAuthentationTest.cs +++ b/test/E2ETests/NtlmAuthentationTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Net.Http; using DeploymentHelpers; @@ -26,14 +25,8 @@ namespace E2ETests using (logger.BeginScope("NtlmAuthenticationTest")) { - var stopwatch = Stopwatch.StartNew(); - - logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", - serverType, runtimeFlavor, architecture, applicationBaseUrl); - var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var connectionString = string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName); - logger.LogInformation("Pointing MusicStore DB to '{connString}'", connectionString); var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(), serverType, runtimeFlavor, architecture) { @@ -53,7 +46,9 @@ namespace E2ETests // Override the connection strings using environment based configuration deploymentParameters.EnvironmentVariables - .Add(new KeyValuePair("SQLAZURECONNSTR_DefaultConnection", connectionString)); + .Add(new KeyValuePair( + "SQLAZURECONNSTR_DefaultConnection", + string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName))); bool testSuccessful = false; @@ -72,16 +67,12 @@ namespace E2ETests return response; }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); - logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); - var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); validator.VerifyNtlmHomePage(response); //Should be able to access the store as the Startup adds necessary permissions for the current user validator.AccessStoreWithPermissions(); - stopwatch.Stop(); - logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } diff --git a/test/E2ETests/OpenIdConnectTests.cs b/test/E2ETests/OpenIdConnectTests.cs index debc2f9fde..8f0e8d67f1 100644 --- a/test/E2ETests/OpenIdConnectTests.cs +++ b/test/E2ETests/OpenIdConnectTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Net.Http; using DeploymentHelpers; using Microsoft.AspNet.Testing.xunit; @@ -37,14 +36,8 @@ namespace E2ETests using (logger.BeginScope("OpenIdConnectTestSuite")) { - var stopwatch = Stopwatch.StartNew(); - - logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", - serverType, runtimeFlavor, architecture, applicationBaseUrl); - var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var connectionString = string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName); - logger.LogInformation("Pointing MusicStore DB to '{connString}'", connectionString); var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(), serverType, runtimeFlavor, architecture) { @@ -62,7 +55,9 @@ namespace E2ETests // Override the connection strings using environment based configuration deploymentParameters.EnvironmentVariables - .Add(new KeyValuePair("SQLAZURECONNSTR_DefaultConnection", connectionString)); + .Add(new KeyValuePair( + "SQLAZURECONNSTR_DefaultConnection", + string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName))); bool testSuccessful = false; @@ -81,16 +76,12 @@ namespace E2ETests return response; }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); - logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); - var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); validator.VerifyHomePage(response); // OpenIdConnect login. validator.LoginWithOpenIdConnect(); - stopwatch.Stop(); - logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } diff --git a/test/E2ETests/PublishAndRunTests.cs b/test/E2ETests/PublishAndRunTests.cs index 6ddcb23228..fffa3df7b9 100644 --- a/test/E2ETests/PublishAndRunTests.cs +++ b/test/E2ETests/PublishAndRunTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Net.Http; using DeploymentHelpers; @@ -58,14 +57,8 @@ namespace E2ETests using (logger.BeginScope("Publish_And_Run_Tests")) { - var stopwatch = Stopwatch.StartNew(); - - logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", - serverType, runtimeFlavor, architecture, applicationBaseUrl); - var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); var connectionString = string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName); - logger.LogInformation("Pointing MusicStore DB to '{connString}'", connectionString); var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(), serverType, runtimeFlavor, architecture) { @@ -84,7 +77,9 @@ namespace E2ETests // Override the connection strings using environment based configuration deploymentParameters.EnvironmentVariables - .Add(new KeyValuePair("SQLAZURECONNSTR_DefaultConnection", connectionString)); + .Add(new KeyValuePair( + "SQLAZURECONNSTR_DefaultConnection", + string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName))); bool testSuccessful = false; @@ -104,8 +99,6 @@ namespace E2ETests return response; }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); - logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); - var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); validator.VerifyHomePage(response); @@ -120,8 +113,6 @@ namespace E2ETests } } - stopwatch.Stop(); - logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds.", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; } diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index 26aef4143a..6417730a20 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Net.Http; using DeploymentHelpers; using Microsoft.AspNet.Testing.xunit; @@ -124,14 +123,7 @@ namespace E2ETests using (logger.BeginScope("SmokeTestSuite")) { - var stopwatch = Stopwatch.StartNew(); - - logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}", - serverType, donetFlavor, architecture, applicationBaseUrl); - var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); - var connectionString = string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName); - logger.LogInformation("Pointing MusicStore DB to '{connString}'", connectionString); var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(), serverType, donetFlavor, architecture) { @@ -152,7 +144,9 @@ namespace E2ETests // Override the connection strings using environment based configuration deploymentParameters.EnvironmentVariables - .Add(new KeyValuePair("SQLAZURECONNSTR_DefaultConnection", connectionString)); + .Add(new KeyValuePair( + "SQLAZURECONNSTR_DefaultConnection", + string.Format(DbUtils.CONNECTION_STRING_FORMAT, musicStoreDbName))); bool testSuccessful = false; @@ -173,8 +167,6 @@ namespace E2ETests return response; }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); - logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds); - var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); validator.VerifyHomePage(response); @@ -260,8 +252,6 @@ namespace E2ETests // MicrosoftAccountLogin validator.LoginWithMicrosoftAccount(); - stopwatch.Stop(); - logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds); testSuccessful = true; }