Skip to content

Commit

Permalink
Fix flaky runtime images unit test related to appinsights injection
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
arroyc authored May 10, 2019
1 parent 684373b commit 16b2c67
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 58 deletions.
5 changes: 3 additions & 2 deletions tests/Oryx.Integration.Tests/NodeEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Microsoft.Oryx.Integration.Tests
{
[Trait("category", "node")]
public class NodeEndToEndTests : PlatformEndToEndTestsBase
{
private const int HostPort = Constants.NodeEndToEndTestsPort;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}

Expand Down
63 changes: 8 additions & 55 deletions tests/Oryx.RuntimeImage.Tests/NodeImagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DockerVolume> { 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 {
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions vsts/pipelines/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- Job_RuntimeImages
pool:
name: OryxLinux
timeoutInMinutes: 150
steps:
- script: |
echo "##vso[task.setvariable variable=BuildBuildImages;]false"
Expand Down
2 changes: 1 addition & 1 deletion vsts/scripts/pullandretag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16b2c67

Please sign in to comment.