Skip to content

Commit d53479c

Browse files
CopilotEvangelink
andcommitted
Collect all dump files in directory including child process dumps
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
1 parent 8df1ee6 commit d53479c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Platform/Microsoft.Testing.Extensions.CrashDump/CrashDumpProcessLifetimeHandler.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,23 @@ public async Task OnTestHostProcessExitedAsync(ITestHostProcessInformation testH
6666
await _outputDisplay.DisplayAsync(this, new ErrorMessageOutputDeviceData(string.Format(CultureInfo.InvariantCulture, CrashDumpResources.CrashDumpProcessCrashedDumpFileCreated, testHostProcessInformation.PID)), cancellation).ConfigureAwait(false);
6767

6868
string expectedDumpFile = _netCoreCrashDumpGeneratorConfiguration.DumpFileNamePattern.Replace("%p", testHostProcessInformation.PID.ToString(CultureInfo.InvariantCulture));
69-
if (File.Exists(expectedDumpFile))
69+
string dumpDirectory = Path.GetDirectoryName(expectedDumpFile)!;
70+
71+
// Collect all dump files in the directory to capture crashes from child processes
72+
bool foundExpectedDump = false;
73+
foreach (string dumpFile in Directory.GetFiles(dumpDirectory, "*.dmp"))
7074
{
71-
await _messageBus.PublishAsync(this, new FileArtifact(new FileInfo(expectedDumpFile), CrashDumpResources.CrashDumpArtifactDisplayName, CrashDumpResources.CrashDumpArtifactDescription)).ConfigureAwait(false);
75+
if (string.Equals(dumpFile, expectedDumpFile, StringComparison.OrdinalIgnoreCase))
76+
{
77+
foundExpectedDump = true;
78+
}
79+
80+
await _messageBus.PublishAsync(this, new FileArtifact(new FileInfo(dumpFile), CrashDumpResources.CrashDumpArtifactDisplayName, CrashDumpResources.CrashDumpArtifactDescription)).ConfigureAwait(false);
7281
}
73-
else
82+
83+
if (!foundExpectedDump)
7484
{
7585
await _outputDisplay.DisplayAsync(this, new ErrorMessageOutputDeviceData(string.Format(CultureInfo.InvariantCulture, CrashDumpResources.CannotFindExpectedCrashDumpFile, expectedDumpFile)), cancellation).ConfigureAwait(false);
76-
foreach (string dumpFile in Directory.GetFiles(Path.GetDirectoryName(expectedDumpFile)!, "*.dmp"))
77-
{
78-
await _messageBus.PublishAsync(this, new FileArtifact(new FileInfo(dumpFile), CrashDumpResources.CrashDumpDisplayName, CrashDumpResources.CrashDumpArtifactDescription)).ConfigureAwait(false);
79-
}
8086
}
8187
}
8288
}

0 commit comments

Comments
 (0)