From 3d608f0469c67fd2984c7f3b7ed1ab44608fd515 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Fri, 23 Aug 2024 09:03:43 +0700 Subject: [PATCH] Leave MongoDB container around if test failed Also print instructions for deleting it once post-failure investigation is completed. --- src/LfMerge.Core.Tests/E2E/E2ETestBase.cs | 1 - src/LfMerge.Core.Tests/SRTestEnvironment.cs | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/LfMerge.Core.Tests/E2E/E2ETestBase.cs b/src/LfMerge.Core.Tests/E2E/E2ETestBase.cs index b7d6ae32..636de998 100644 --- a/src/LfMerge.Core.Tests/E2E/E2ETestBase.cs +++ b/src/LfMerge.Core.Tests/E2E/E2ETestBase.cs @@ -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); diff --git a/src/LfMerge.Core.Tests/SRTestEnvironment.cs b/src/LfMerge.Core.Tests/SRTestEnvironment.cs index 11b835a6..a344a255 100644 --- a/src/LfMerge.Core.Tests/SRTestEnvironment.cs +++ b/src/LfMerge.Core.Tests/SRTestEnvironment.cs @@ -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); @@ -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)"}"); } } } @@ -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; } } @@ -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); }