Skip to content

Commit 3239112

Browse files
authored
Make BundledAppWithSubDirs clean up bundled apps after each test case instead of after all tests (#120611)
The `BundledAppWithSubDirs` tests intermittently hit out of space issues in CI. They do clean up the bundled apps they create, but only after all tests in the class have run. This change makes those tests clean up earlier for environments that may not have the space for all the bundled apps at the same time. This also fixes the one case where we were leaving an extracted file (`mockcoreclr`) behind on non-Windows.
1 parent a09317d commit 3239112

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/installer/tests/AppHost.Bundle.Tests/BundleExtractToSpecificPath.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ private void UndefinedHOME_getpwuidFallback()
224224
DirectoryInfo expectedExtractDir = sharedTestState.SelfContainedApp.GetExtractionDir(Path.Combine(home, ".net"), bundledApp.Manifest);
225225
var extractedFiles = GetExpectedExtractedFiles(bundledApp.Manifest, bundledApp.Options);
226226
expectedExtractDir.Should().HaveFiles(extractedFiles);
227+
228+
// Extraction directory for this test is not associated with the SingleFileTestApp, so we need to explicitly delete it.
229+
Directory.Delete(expectedExtractDir.FullName, recursive: true);
227230
}
228231

229232
private static List<string> GetExpectedExtractedFiles(Manifest manifest, BundleOptions bundleOptions)

src/installer/tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ public BundledAppWithSubDirs(SharedTestState fixture)
2020
sharedTestState = fixture;
2121
}
2222

23-
private FluentAssertions.AndConstraint<CommandResultAssertions> RunTheApp(string path, bool selfContained, bool deleteExtracted = true)
23+
private FluentAssertions.AndConstraint<CommandResultAssertions> RunTheApp(string path, bool selfContained, bool deleteApp = true)
2424
{
2525
CommandResult result = Command.Create(path)
2626
.EnableTracingAndCaptureOutputs()
2727
.DotNetRoot(selfContained ? null : TestContext.BuiltDotNet.BinPath)
2828
.MultilevelLookup(false)
2929
.Execute();
30-
if (deleteExtracted)
30+
if (deleteApp)
3131
{
3232
DeleteExtractionDirectory(result);
33+
34+
// Delete the bundled app itself. It would already be cleaned up after all tests in this class run, but
35+
// we do this early for test environments that may not have enough space for all the bundled apps at once.
36+
FileUtils.DeleteFileIfPossible(path);
3337
}
3438

3539
return result.Should().Pass()
@@ -65,7 +69,7 @@ public void FrameworkDependent(BundleOptions options)
6569

6670
// Run the bundled app
6771
bool shouldExtract = options.HasFlag(BundleOptions.BundleAllContent);
68-
RunTheApp(singleFile, selfContained: false, deleteExtracted: !shouldExtract)
72+
RunTheApp(singleFile, selfContained: false, deleteApp: !shouldExtract)
6973
.And.CreateExtraction(shouldExtract);
7074

7175
if (shouldExtract)
@@ -87,7 +91,7 @@ public void SelfContained(BundleOptions options)
8791

8892
// Run the bundled app
8993
bool shouldExtract = options.HasFlag(BundleOptions.BundleAllContent);
90-
RunTheApp(singleFile, selfContained: true, deleteExtracted: !shouldExtract)
94+
RunTheApp(singleFile, selfContained: true, deleteApp: !shouldExtract)
9195
.And.CreateExtraction(shouldExtract);
9296

9397
if (shouldExtract)
@@ -107,7 +111,7 @@ public void SelfContained_Targeting50(BundleOptions options)
107111

108112
// Run the bundled app
109113
bool shouldExtract = options.HasFlag(BundleOptions.BundleAllContent);
110-
RunTheApp(singleFile, selfContained: true, deleteExtracted: !shouldExtract)
114+
RunTheApp(singleFile, selfContained: true, deleteApp: !shouldExtract)
111115
.And.CreateExtraction(shouldExtract);
112116

113117
if (shouldExtract)
@@ -127,7 +131,7 @@ public void FrameworkDependent_Targeting50(BundleOptions options)
127131

128132
// Run the bundled app
129133
bool shouldExtract = options.HasFlag(BundleOptions.BundleAllContent);
130-
RunTheApp(singleFile, selfContained: false, deleteExtracted: !shouldExtract)
134+
RunTheApp(singleFile, selfContained: false, deleteApp: !shouldExtract)
131135
.And.CreateExtraction(shouldExtract);
132136

133137
if (shouldExtract)

0 commit comments

Comments
 (0)