Skip to content

Commit

Permalink
Rework container app shutdown sequence, other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jul 21, 2023
1 parent d454576 commit 60b3999
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using NewRelic.Agent.IntegrationTestHelpers;
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;
Expand All @@ -18,6 +19,7 @@ public class ContainerApplication : RemoteApplication

private readonly string _applicationDirectoryName;
private readonly string _distroTag;
private readonly string _arch;

protected override string ApplicationDirectoryName => _applicationDirectoryName;

Expand All @@ -29,15 +31,18 @@ protected override string SourceApplicationDirectoryPath
}
}

public ContainerApplication(string applicationDirectoryName, string distroTag) : base(applicationType: ApplicationType.Container, isCoreApp: true)
public ContainerApplication(string applicationDirectoryName, string distroTag, string arch) : base(applicationType: ApplicationType.Container, isCoreApp: true)
{
_applicationDirectoryName = applicationDirectoryName;
_distroTag = distroTag;
_arch = arch;
}

public override string AppName => $"ContainerApplication: {_distroTag}";

public override void CopyToRemote()
{
CopyNewRelicHomeCoreClrLinuxDirectoryToRemote("x64");
CopyNewRelicHomeCoreClrLinuxDirectoryToRemote(_arch);

ModifyNewRelicConfig();
}
Expand Down Expand Up @@ -131,10 +136,12 @@ public override void Shutdown()
return;
}

TestLogger?.WriteLine($"[ContainerApplication] Sending shutdown signal to {_distroTag}.");
TestLogger?.WriteLine($"[{AppName}] Sending shutdown signal to smoketestapp container.");

// Because we are using docker compose we can just send the kill signal to cause docker compose to shutdown
RemoteProcess.Kill();
// stop and remove the container, no need to kill RemoteProcess, as it will die when this command runs
// wait up to 5 seconds for the app to terminate gracefully before forcefully closing it
Process.Start("docker", "container stop smoketestapp -t 5");
Process.Start("docker", "container rm smoketestapp");
}

protected virtual void WaitForAppServerToStartListening(Process process, bool captureStandardOutput)
Expand Down Expand Up @@ -162,13 +169,13 @@ protected virtual void WaitForAppServerToStartListening(Process process, bool ca
}
catch (Exception)
{
TestLogger?.WriteLine("[RemoteService]: WaitForAppServerToStartListening could not kill hung remote process.");
TestLogger?.WriteLine($"[{AppName}]: WaitForAppServerToStartListening could not kill hung remote process.");
}
}

if (captureStandardOutput)
{
CapturedOutput.WriteProcessOutputToLog("[RemoteService]: WaitForAppServerToStartListening");
CapturedOutput.WriteProcessOutputToLog($"[{AppName}]: WaitForAppServerToStartListening");
}

Assert.Fail("Remote process never generated a .pid file!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NewRelic.Agent.ContainerIntegrationTests.ContainerFixtures
public class SmokeTestFixture : ContainerFixture
{
public SmokeTestFixture() :
base(new ContainerApplication("SmokeTestApp", "7.0-jammy-amd64"))
base(new ContainerApplication("SmokeTestApp", "7.0-jammy-amd64", "x64"))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Linq;
using NewRelic.Agent.ContainerIntegrationTests.ContainerFixtures;
using NewRelic.Agent.IntegrationTestHelpers;
using Xunit;
Expand All @@ -19,13 +18,18 @@ public LinuxSmokeTest(SmokeTestFixture fixture, ITestOutputHelper output) : base
_fixture = fixture;
_fixture.TestLogger = output;

_fixture.Actions(exerciseApplication: () =>
{
_fixture.GetWeatherForcast();
// Containerized apps are shutdown by killing the process so we need to wait for data that we expect here
_fixture.AgentLog.WaitForLogLine(AgentLogBase.HarvestFinishedLogLineRegex, TimeSpan.FromMinutes(1.5));
});
_fixture.Actions(setupConfiguration: () =>
{
var configModifier = new NewRelicConfigModifier(_fixture.DestinationNewRelicConfigFilePath);
configModifier.ConfigureFasterMetricsHarvestCycle(5);
},
exerciseApplication: () =>
{
_fixture.GetWeatherForcast();
// Containerized apps are shutdown by killing the process so we need to wait for data that we expect here
_fixture.AgentLog.WaitForLogLine(AgentLogBase.HarvestFinishedLogLineRegex, TimeSpan.FromMinutes(1.5));
});

_fixture.Initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public RemoteApplication SetAdditionalEnvironmentVariables(IDictionary<string, s

protected Process RemoteProcess { get; set; }

public string AppName = "IntegrationTestAppName";
public virtual string AppName => "IntegrationTestAppName";

private string _uniqueFolderName;
public string UniqueFolderName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public virtual void Initialize()

do
{
TestLogger?.WriteLine("Test Home" + RemoteApplication.DestinationNewRelicHomeDirectoryPath);
TestLogger?.WriteLine("Test Home: " + RemoteApplication.DestinationNewRelicHomeDirectoryPath);

// reset these for each loop iteration
applicationHadNonZeroExitCode = false;
Expand Down

0 comments on commit 60b3999

Please sign in to comment.