Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public HangDumpActivityIndicator(
_environment = environment;
_task = task;
_clock = clock;
if (_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey))
if (_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName))
{
string namedPipeSuffix = _environment.GetEnvironmentVariable(HangDumpConfiguration.MutexNameSuffix)
?? throw new InvalidOperationException($"Expected {HangDumpConfiguration.MutexNameSuffix} environment variable set.");
Expand All @@ -82,8 +81,7 @@ public HangDumpActivityIndicator(

public string Description => ExtensionResources.HangDumpExtensionDescription;

public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey));
public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName));

public async Task OnTestSessionStartingAsync(ITestSessionContext testSessionContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public HangDumpEnvironmentVariableProvider(ICommandLineOptions commandLineOption

public string Description => ExtensionResources.HangDumpExtensionDescription;

public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey));
public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName));

public Task UpdateAsync(IEnvironmentVariables environmentVariables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public HangDumpProcessLifetimeHandler(

public Type[] DataTypesProduced => [typeof(FileArtifact)];

public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey));
public Task<bool> IsEnabledAsync() => Task.FromResult(_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName));

public async Task BeforeTestHostProcessStartAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ public async Task HangDump_DefaultSetting_CreateDump(string tfm)
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{testHostResult}'");
}

[TestMethod]
public async Task HangDump_WithDotnetTest_CreateDump()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// TODO: Investigate failures on macos
return;
}

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);

DotnetMuxerResult testResult = await DotnetCli.RunAsync(
$"test --project \"{AssetFixture.TargetAssetPath}\" --hangdump --hangdump-timeout 8s --results-directory \"{resultDirectory}\"",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
environmentVariables: new Dictionary<string, string?>
{
{ "SLEEPTIMEMS1", "4000" },
{ "SLEEPTIMEMS2", "600000" },
},
workingDirectory: AssetFixture.TargetAssetPath,
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);

testResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "HangDump*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsNotNull(dumpFile, $"Dump file not found when running with 'dotnet test'\n{testResult}'");
}

[TestMethod]
public async Task HangDump_CustomFileName_CreateDump()
{
Expand Down
Loading