From 16b2c671e68cfff930b4f86c86d719f45560b320 Mon Sep 17 00:00:00 2001 From: Arjun Roy Chaudhuri Date: Fri, 10 May 2019 13:48:21 -0700 Subject: [PATCH] Fix flaky runtime images unit test related to appinsights injection * increasing timeout for integration tests and changing sampleapp in runtime images unit test to avoid concurrency issue * update script with option to fail when any single command fails * adding some comments to appinsights tests * getting rid of extra tests in node runtime and optimize node integration test for appinsights --- .../NodeEndToEndTests.cs | 5 +- .../Oryx.RuntimeImage.Tests/NodeImagesTest.cs | 63 +++---------------- vsts/pipelines/nightly.yml | 1 + vsts/scripts/pullandretag.sh | 2 +- 4 files changed, 13 insertions(+), 58 deletions(-) diff --git a/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs b/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs index f1a0973972..efdb2fb7ae 100644 --- a/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs +++ b/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Oryx.Integration.Tests { + [Trait("category", "node")] public class NodeEndToEndTests : PlatformEndToEndTestsBase { private const int HostPort = Constants.NodeEndToEndTestsPort; @@ -372,7 +373,7 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( public async Task CanBuildAndRun_NodeApp_WithAppInsights_Configured(string nodeVersion) { // Arrange - var appName = "webfrontend"; + var appName = "linxnodeexpress"; var hostDir = Path.Combine(_hostSamplesDir, "nodejs", appName); var volume = DockerVolume.Create(hostDir); var appDir = volume.ContainerDir; @@ -419,7 +420,7 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( async () => { var data = await _httpClient.GetStringAsync($"http://localhost:{HostPort}/"); - Assert.Contains("Say It Again", data); + Assert.Contains("Hello World from express!", data); }); } diff --git a/tests/Oryx.RuntimeImage.Tests/NodeImagesTest.cs b/tests/Oryx.RuntimeImage.Tests/NodeImagesTest.cs index 63769e43fd..3f7528a7d4 100644 --- a/tests/Oryx.RuntimeImage.Tests/NodeImagesTest.cs +++ b/tests/Oryx.RuntimeImage.Tests/NodeImagesTest.cs @@ -346,66 +346,20 @@ await EndToEndTestHelper.RunAndAssertAppAsync( } - [Theory] - [MemberData(nameof(TestValueGenerator.GetNodeVersions_SupportDebugging), MemberType = typeof(TestValueGenerator))] - public async Task GeneratesScript_CanRun_AppInsightsModule_Found(string nodeVersion) - { - // Arrange - var imageName = string.Concat("oryxdevms/node-", nodeVersion); - var hostSamplesDir = Path.Combine(Directory.GetCurrentDirectory(), "SampleApps"); - var volume = DockerVolume.Create(Path.Combine(hostSamplesDir, "nodejs", "webfrontend")); - var appDir = volume.ContainerDir; - var manifestFileContent = "injectedAppInsight=\"True\""; - var aiNodesdkLoaderContent = @"try { - var appInsights = require('applicationinsights'); - if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) - { - appInsights.setup().start(); - } - }catch (e) { - console.log(e); - } "; - - int hostPort = 8585; - int containerDebugPort = 8080; - - var script = new ShellScriptBuilder() - .CreateFile(appDir + "/oryx-manifest.toml", manifestFileContent) - .CreateFile(appDir + "/oryx-appinsightsloader.js", aiNodesdkLoaderContent) - .AddCommand($"cd {appDir}") - .AddCommand("npm install") - .AddCommand("npm install --save applicationinsights") - .AddCommand($"oryx -appPath {appDir}") - .AddDirectoryExistsCheck($"{appDir}/node_modules") - .AddDirectoryExistsCheck($"{appDir}/node_modules/applicationinsights") - .AddCommand("./run.sh") - .ToString(); - - await EndToEndTestHelper.RunAndAssertAppAsync( - imageName: $"oryxdevms/node-{nodeVersion}", - output: _output, - volumes: new List { volume }, - environmentVariables: null, - portMapping: $"{hostPort}:{containerDebugPort}", - link: null, - runCmd: "/bin/sh", - runArgs: new[] { "-c", script }, - assertAction: async () => - { - var data = await _httpClient.GetStringAsync($"http://localhost:{hostPort}/"); - Assert.Contains("Say It Again", data); - }, - dockerCli: _dockerCli); - } - [Theory] [MemberData(nameof(TestValueGenerator.GetNodeVersions_SupportDebugging), MemberType = typeof(TestValueGenerator))] public async Task GeneratesScript_CanRun_AppInsightsModule_NotFound(string nodeVersion) { + // This test is for the following scenario: + // When we find injectedAppInsight=True in the manifest file, we assume that appinsights + // has been injected and it's installed during build (npm install). But for some reason if we + // don't see the appinsights node_module we shouldn't break the app. We should run the app + // and additionally print the exception message + // Arrange var imageName = string.Concat("oryxdevms/node-", nodeVersion); var hostSamplesDir = Path.Combine(Directory.GetCurrentDirectory(), "SampleApps"); - var volume = DockerVolume.Create(Path.Combine(hostSamplesDir, "nodejs", "webfrontend")); + var volume = DockerVolume.Create(Path.Combine(hostSamplesDir, "nodejs", "linxnodeexpress")); var appDir = volume.ContainerDir; var manifestFileContent = "injectedAppInsight=\"True\""; var aiNodesdkLoaderContent = @"try { @@ -432,7 +386,6 @@ public async Task GeneratesScript_CanRun_AppInsightsModule_NotFound(string nodeV .AddCommand("./run.sh") .ToString(); - await EndToEndTestHelper.RunAndAssertAppAsync( imageName: $"oryxdevms/node-{nodeVersion}", output: _output, @@ -445,7 +398,7 @@ await EndToEndTestHelper.RunAndAssertAppAsync( assertAction: async () => { var data = await _httpClient.GetStringAsync($"http://localhost:{hostPort}/"); - Assert.Contains("Say It Again", data); + Assert.Contains("Hello World from express!", data); }, dockerCli: _dockerCli); } diff --git a/vsts/pipelines/nightly.yml b/vsts/pipelines/nightly.yml index 9edbd47abf..7ff80c44e6 100644 --- a/vsts/pipelines/nightly.yml +++ b/vsts/pipelines/nightly.yml @@ -55,6 +55,7 @@ jobs: - Job_RuntimeImages pool: name: OryxLinux + timeoutInMinutes: 150 steps: - script: | echo "##vso[task.setvariable variable=BuildBuildImages;]false" diff --git a/vsts/scripts/pullandretag.sh b/vsts/scripts/pullandretag.sh index 4cd809a836..c08d7c8616 100644 --- a/vsts/scripts/pullandretag.sh +++ b/vsts/scripts/pullandretag.sh @@ -4,7 +4,7 @@ # Licensed under the MIT license. # -------------------------------------------------------------------------------------------- -set -o pipefail +set -euo pipefail while read sourceImage; do # Always use specific build number based tag and then use the same tag to create a 'latest' tag and push it