Skip to content

Commit

Permalink
Dispose SRTestEnv during test TearDown method
Browse files Browse the repository at this point in the history
We keep the temp directory around if the test failed, but we dispose
everything else.
  • Loading branch information
rmunn committed Aug 22, 2024
1 parent b3e258d commit 5fe1d6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/LfMerge.Core.Tests/E2E/E2ETestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task FixtureSetup()
// Ensure sena-3.zip is available to all tests as a starting point
Sena3ZipPath = Path.Combine(TestDataFolder.Path, "sena-3.zip");
if (!File.Exists(Sena3ZipPath)) {
var testEnv = new SRTestEnvironment(TempFolderForTest);
using var testEnv = new SRTestEnvironment(TempFolderForTest);
if (!await testEnv.IsLexBoxAvailable()) {
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.");
}
Expand Down Expand Up @@ -96,16 +96,17 @@ public async Task TestSetup()
[TearDown]
public async Task TestTeardown()
{
var outcome = TestContext.CurrentContext.Result.Outcome;
var success = outcome == ResultState.Success || outcome == ResultState.Ignored;
// Only delete temp folder if test passed, otherwise we'll want to leave it in place for post-test investigation
if (TestContext.CurrentContext.Result.Outcome == ResultState.Success) {
TempFolderForTest.Dispose();
if (ProjectIdToDelete is not null) {
var projId = ProjectIdToDelete.Value;
ProjectIdToDelete = null;
// Also leave LexBox project in place for post-test investigation, even though this might tend to clutter things up a little
await TestEnv.DeleteLexBoxProject(projId);
}
TestEnv.DeleteTempFolderDuringCleanup = success;
// Also leave LexBox project in place for post-test investigation, even though this might tend to clutter things up a little
if (success && ProjectIdToDelete is not null) {
var projId = ProjectIdToDelete.Value;
ProjectIdToDelete = null;
await TestEnv.DeleteLexBoxProject(projId);
}
TestEnv.Dispose();
}

public string TestFolderForProject(string projectCode) => Path.Join(TempFolderForTest.Path, "webwork", projectCode);
Expand Down
4 changes: 3 additions & 1 deletion src/LfMerge.Core.Tests/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TestEnvironment : IDisposable
protected readonly TemporaryFolder _languageForgeServerFolder;
private readonly bool _resetLfProjectsDuringCleanup;
private readonly bool _releaseSingletons;
public bool DeleteTempFolderDuringCleanup { get; set; } = true;
public LfMergeSettings Settings;
private readonly MongoConnectionDouble _mongoConnection;
public ILogger Logger => MainClass.Logger;
Expand Down Expand Up @@ -107,7 +108,8 @@ public void Dispose()
MainClass.Container = null;
if (_resetLfProjectsDuringCleanup)
LanguageForgeProjectAccessor.Reset();
_languageForgeServerFolder?.Dispose();
if (DeleteTempFolderDuringCleanup)
_languageForgeServerFolder?.Dispose();
Settings = null;
if (_releaseSingletons)
SingletonsContainer.Release();
Expand Down

0 comments on commit 5fe1d6d

Please sign in to comment.