From 0047cd1df33e0897a2b9661978bfba549d970f09 Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Thu, 23 May 2019 12:55:51 -0700 Subject: [PATCH] Use InMemory channel in functional tests (#1204) * Use InMemooryChannel for predictable flush and minor improvements * and web funs * clean up * Docker container recreation fixes --- Test/E2ETests/E2ETests/Test452Base.cs | 9 +++--- .../E2ETests/net471/Test452OnNet471.cs | 7 ++-- .../E2ETestApp/ApplicationInsights.config | 2 +- .../E2ETestWebApi/ApplicationInsights.config | 2 +- .../Controllers/ExternalCallsController.cs | 12 ++++--- .../NetCore20/E2ETestAppCore20/Startup.cs | 32 +++++++++++++------ .../ApplicationInsights.config | 4 +-- .../Aspx45/ApplicationInsights.config | 4 +-- .../ConsoleAppFW45/ApplicationInsights.config | 3 +- .../ApplicationInsights.config | 4 +-- .../Wa45Aspx/ApplicationInsights.config | 4 +-- .../Wcf45Tests/ApplicationInsights.config | 4 +-- .../WebAppFW45/ApplicationInsights.config | 2 +- .../ApplicationInsights.config | 5 ++- 14 files changed, 53 insertions(+), 41 deletions(-) diff --git a/Test/E2ETests/E2ETests/Test452Base.cs b/Test/E2ETests/E2ETests/Test452Base.cs index cdb55fbc..7a90493e 100644 --- a/Test/E2ETests/E2ETests/Test452Base.cs +++ b/Test/E2ETests/E2ETests/Test452Base.cs @@ -74,12 +74,13 @@ namespace E2ETests GetDockerCompose(); Trace.WriteLine("Getting docker-compose.exe completed."); - //DockerUtils.RemoveDockerImage(Apps[AppNameBeingTested].imageName, true); - //DockerUtils.RemoveDockerContainer(Apps[AppNameBeingTested].containerName, true); + DockerUtils.RemoveDockerImage(Apps[AppNameBeingTested].imageName, true); + DockerUtils.RemoveDockerContainer(Apps[AppNameBeingTested].containerName, true); // Deploy the docker cluster using Docker-Compose - //DockerUtils.ExecuteDockerComposeCommand("up -d --force-recreate --build", DockerComposeFileName); - DockerUtils.ExecuteDockerComposeCommand("up -d --build", DockerComposeFileName); + DockerUtils.ExecuteDockerComposeCommand("up -d --force-recreate --build", DockerComposeFileName); + + //DockerUtils.ExecuteDockerComposeCommand("up -d --build", DockerComposeFileName); Thread.Sleep(5000); DockerUtils.PrintDockerProcessStats("Docker-Compose -build"); diff --git a/Test/E2ETests/E2ETests/net471/Test452OnNet471.cs b/Test/E2ETests/E2ETests/net471/Test452OnNet471.cs index 34934ce1..88a8b39c 100644 --- a/Test/E2ETests/E2ETests/net471/Test452OnNet471.cs +++ b/Test/E2ETests/E2ETests/net471/Test452OnNet471.cs @@ -7,8 +7,8 @@ namespace E2ETests.net471 [TestClass] public class Test452OnNet471 : Test452Base { - private static string VersionPrefix; - private static string VersionPrefixSql; + private const string VersionPrefix = "rdddsd"; + private const string VersionPrefixSql = "rddf"; public TestContext TestContext { get; set; } @@ -18,9 +18,6 @@ namespace E2ETests.net471 DockerComposeFileName = "docker-compose452AppOn471.yml"; AppNameBeingTested = TestConstants.WebAppName; - VersionPrefix = "rdddsd"; - VersionPrefixSql = "rddf"; - if (!Apps.ContainsKey(AppNameBeingTested)) { Apps.Add(AppNameBeingTested, new DeployedApp diff --git a/Test/E2ETests/TestApps/Net452/E2ETestApp/ApplicationInsights.config b/Test/E2ETests/TestApps/Net452/E2ETestApp/ApplicationInsights.config index 7ab13dd9..093b3694 100644 --- a/Test/E2ETests/TestApps/Net452/E2ETestApp/ApplicationInsights.config +++ b/Test/E2ETests/TestApps/Net452/E2ETestApp/ApplicationInsights.config @@ -79,7 +79,7 @@ Event - + http://e2etests_ingestionservice_1/api/Data/PushItem true diff --git a/Test/E2ETests/TestApps/Net452/E2ETestWebApi/ApplicationInsights.config b/Test/E2ETests/TestApps/Net452/E2ETestWebApi/ApplicationInsights.config index 4e9b1fa4..5fa3a955 100644 --- a/Test/E2ETests/TestApps/Net452/E2ETestWebApi/ApplicationInsights.config +++ b/Test/E2ETests/TestApps/Net452/E2ETestWebApi/ApplicationInsights.config @@ -98,7 +98,7 @@ Event - + http://e2etests_ingestionservice_1/api/Data/PushItem true diff --git a/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Controllers/ExternalCallsController.cs b/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Controllers/ExternalCallsController.cs index 1d2c9fdd..873d99c5 100644 --- a/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Controllers/ExternalCallsController.cs +++ b/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Controllers/ExternalCallsController.cs @@ -12,7 +12,6 @@ namespace E2ETestAppCore20.Controllers [Route("external/calls")] public class ExternalCallsController : Controller { - private const string UrlWithNonexistentHostName = "http://abcdefzzzzeeeeadadad.com"; private const string UrlTestWebApiGetCallTemplate = "http://{0}:80/api/values"; public const string UrlWhichReturns500Format = "http://{0}:80/api/values/999"; @@ -49,12 +48,14 @@ namespace E2ETestAppCore20.Controllers /// private const string QueryToExecuteLabel = "Query Executed:"; + private readonly TelemetryConfiguration telemetryConfiguration; + private string GetQueryValue(string valueKey) { return Request.Query[valueKey].ToString(); } - public ExternalCallsController(IOptions options) + public ExternalCallsController(IOptions options, TelemetryConfiguration telemetryConfiguration) { if (string.IsNullOrEmpty(ConnectionString)) { @@ -64,6 +65,7 @@ namespace E2ETestAppCore20.Controllers var webApiHostName = options.Value.Webapihostname; UrlTestWebApiGetCall = string.Format(UrlTestWebApiGetCallTemplate, webApiHostName); UrlWhichReturns500 = string.Format(UrlWhichReturns500Format, webApiHostName); + this.telemetryConfiguration = telemetryConfiguration; } // GET external/calls @@ -89,7 +91,7 @@ namespace E2ETestAppCore20.Controllers { case "flush": title = response = "Flushed telemetry channel"; - TelemetryConfiguration.Active.TelemetryChannel.Flush(); + telemetryConfiguration.TelemetryChannel.Flush(); break; case "setsqlserverinstance": string sqlServerInstance = GetQueryValue("server"); @@ -108,8 +110,8 @@ namespace E2ETestAppCore20.Controllers string endPoint = GetQueryValue("endpoint"); if (!string.IsNullOrEmpty(endPoint)) { - TelemetryConfiguration.Active.TelemetryChannel.EndpointAddress = string.Format(Program.EndPointAddressFormat, endPoint); - title = response = "Update Endpoint to: " + TelemetryConfiguration.Active.TelemetryChannel.EndpointAddress; + telemetryConfiguration.TelemetryChannel.EndpointAddress = string.Format(Program.EndPointAddressFormat, endPoint); + title = response = "Update Endpoint to: " + telemetryConfiguration.TelemetryChannel.EndpointAddress; } else { diff --git a/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Startup.cs b/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Startup.cs index 9a6249ef..2eec5849 100644 --- a/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Startup.cs +++ b/Test/E2ETests/TestApps/NetCore20/E2ETestAppCore20/Startup.cs @@ -27,24 +27,36 @@ namespace E2ETestAppCore20 { services.Configure(Configuration); services.AddMvc(); + + services.AddSingleton(provider => + { + var options = provider.GetService>(); + var telemetryConfiguration = new TelemetryConfiguration("fafa4b10-03d3-4bb0-98f4-364f0bdf5df8") + { + TelemetryChannel = + { + DeveloperMode = true, + EndpointAddress = string.Format(Program.EndPointAddressFormat, options.Value.EndPoint) + } + }; + + return telemetryConfiguration; + }); + + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions options) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, + IOptions options, + TelemetryConfiguration configuration, + DependencyTrackingTelemetryModule module) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseMvc(); - - var teleConfig = TelemetryConfiguration.Active; - teleConfig.TelemetryChannel.DeveloperMode = true; - - // Fake endpoint. - teleConfig.TelemetryChannel.EndpointAddress = string.Format(Program.EndPointAddressFormat, options.Value.EndPoint); - teleConfig.InstrumentationKey = "fafa4b10-03d3-4bb0-98f4-364f0bdf5df8"; - - new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active); + module.Initialize(configuration); } } } diff --git a/Test/Web/FunctionalTests/TestApps/AspNetDiagnostics/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/AspNetDiagnostics/ApplicationInsights.config index 8d130d26..881045b2 100644 --- a/Test/Web/FunctionalTests/TestApps/AspNetDiagnostics/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/AspNetDiagnostics/ApplicationInsights.config @@ -42,9 +42,9 @@ - + http://localhost:4000/v2/track - 0:00:01 + true diff --git a/Test/Web/FunctionalTests/TestApps/Aspx45/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/Aspx45/ApplicationInsights.config index bae0edad..cada995b 100644 --- a/Test/Web/FunctionalTests/TestApps/Aspx45/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/Aspx45/ApplicationInsights.config @@ -38,9 +38,9 @@ - + http://localhost:4001/v2/track - 0:00:01 + true diff --git a/Test/Web/FunctionalTests/TestApps/ConsoleAppFW45/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/ConsoleAppFW45/ApplicationInsights.config index 9a10b0e9..a88dee42 100644 --- a/Test/Web/FunctionalTests/TestApps/ConsoleAppFW45/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/ConsoleAppFW45/ApplicationInsights.config @@ -15,8 +15,9 @@ - + http://LocalHost:4002/v2/track + true diff --git a/Test/Web/FunctionalTests/TestApps/Mvc4_MediumTrust/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/Mvc4_MediumTrust/ApplicationInsights.config index b30c7e59..ad8ba998 100644 --- a/Test/Web/FunctionalTests/TestApps/Mvc4_MediumTrust/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/Mvc4_MediumTrust/ApplicationInsights.config @@ -41,9 +41,9 @@ - + http://localhost:4004/v2/track - 0:00:01 + true diff --git a/Test/Web/FunctionalTests/TestApps/Wa45Aspx/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/Wa45Aspx/ApplicationInsights.config index d1b678b7..c5f5c096 100644 --- a/Test/Web/FunctionalTests/TestApps/Wa45Aspx/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/Wa45Aspx/ApplicationInsights.config @@ -37,9 +37,9 @@ - + http://localhost:4005/v2/track - 0:00:01 + true diff --git a/Test/Web/FunctionalTests/TestApps/Wcf45Tests/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/Wcf45Tests/ApplicationInsights.config index 181a78aa..a3b350dc 100644 --- a/Test/Web/FunctionalTests/TestApps/Wcf45Tests/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/Wcf45Tests/ApplicationInsights.config @@ -40,9 +40,9 @@ - + http://LocalHost:4006/v2/track - 0:00:01 + true diff --git a/Test/Web/FunctionalTests/TestApps/WebAppFW45/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/WebAppFW45/ApplicationInsights.config index 4493ca96..8a6065b7 100644 --- a/Test/Web/FunctionalTests/TestApps/WebAppFW45/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/WebAppFW45/ApplicationInsights.config @@ -42,7 +42,7 @@ - + http://LocalHost:4017/v2/track true diff --git a/Test/Web/FunctionalTests/TestApps/WebAppFW45Sampled/ApplicationInsights.config b/Test/Web/FunctionalTests/TestApps/WebAppFW45Sampled/ApplicationInsights.config index 3d6ed0fb..6d243f77 100644 --- a/Test/Web/FunctionalTests/TestApps/WebAppFW45Sampled/ApplicationInsights.config +++ b/Test/Web/FunctionalTests/TestApps/WebAppFW45Sampled/ApplicationInsights.config @@ -42,10 +42,9 @@ - + http://LocalHost:4008/v2/track - false - 0:00:01 + true