Skip to content

Commit

Permalink
Leave MongoDB container around if test failed
Browse files Browse the repository at this point in the history
Also print instructions for deleting it once post-failure investigation
is completed.
  • Loading branch information
rmunn committed Aug 23, 2024
1 parent 6f53b1a commit 3d608f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/LfMerge.Core.Tests/E2E/E2ETestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public async Task TestSetup()
Assert.Ignore("Can't run E2E tests without a copy of LexBox to test against. Please either launch LexBox on localhost port 80, or set the appropriate environment variables to point to a running copy of LexBox.");
}
await TestEnv.Login();
Console.WriteLine("About to launch Mongo...");
TestEnv.LaunchMongo();

MagicStrings.SetMinimalModelVersion(LcmCache.ModelVersion);
Expand Down
12 changes: 7 additions & 5 deletions src/LfMerge.Core.Tests/SRTestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public void LaunchMongo()
{
var result = CommandLineRunner.Run("docker", "run -p 27017 -d mongo:6", ".", 30, NullProgress);
MongoContainerId = result.StandardOutput?.TrimEnd();
Console.WriteLine($"Launched Mongo container {MongoContainerId ?? "(null) - something went wrong"}");
if (MongoContainerId != null)
{
result = CommandLineRunner.Run("docker", $"port {MongoContainerId} 27017", ".", 30, NullProgress);
Expand All @@ -77,7 +76,6 @@ public void LaunchMongo()
Settings.MongoHostname = parts[0].Replace("0.0.0.0", "localhost");
Settings.MongoPort = parts[1];
}
Console.WriteLine($"Mongo is listening on port {parts?[1] ?? hostAndPort + " (oops, mongoPort was null)"}");
}
}
}
Expand All @@ -86,10 +84,8 @@ public void StopMongo()
{
if (MongoContainerId is not null)
{
Console.WriteLine($"Stopping Mongo container {MongoContainerId} ...");
CommandLineRunner.Run("docker", $"stop {MongoContainerId}", ".", 30, NullProgress);
CommandLineRunner.Run("docker", $"rm {MongoContainerId}", ".", 30, NullProgress);
Console.WriteLine($"Stopped Mongo container {MongoContainerId} ...");
MongoContainerId = null;
}
}
Expand All @@ -98,7 +94,13 @@ protected override void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing) {
StopMongo();
if (CleanUpTestData) {
StopMongo();
} else {
Console.WriteLine($"Leaving Mongo container {MongoContainerId} around to examine data on failed test.");
Console.WriteLine($"It is listening on {Settings.MongoDbHostNameAndPort}");
Console.WriteLine($"To delete it, run `docker stop {MongoContainerId} ; docker rm {MongoContainerId}`.");
}
}
base.Dispose(disposing);
}
Expand Down

0 comments on commit 3d608f0

Please sign in to comment.