Skip to content
Open
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description mentions checking both server and pipe cli options but the 2 parts of the implementation don't do that. Is this expected?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth any special casing here at all. Even if this ended up being used in Test Explorer and it doesn't work, I don't think it's a big concern.

{
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 @@ -27,8 +27,37 @@ public async Task HangDump_DefaultSetting_CreateDump(string tfm)
},
cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "HangDump*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{testHostResult}'");
string[] dumpFiles = Directory.GetFiles(resultDirectory, "HangDump*.dmp", SearchOption.AllDirectories);
Assert.ContainsSingle(dumpFiles, $"Expected single dump file. Found: {Environment.NewLine}{string.Join(Environment.NewLine, dumpFiles)}{Environment.NewLine}{testHostResult}");
}

[TestMethod]
public async Task HangDump_WithDotnetTest_CreateDump()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can use the oscondition attribute here instead

{
// 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}\" -f {TargetFrameworks.NetCurrent} --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);

// This should be TestHostProcessExitedNonGracefully instead of GenericFailure. This will likely be fixed by https://github.com/dotnet/sdk/pull/51857
testResult.AssertExitCodeIs(ExitCodes.GenericFailure);
string[] dumpFiles = Directory.GetFiles(resultDirectory, "HangDump*.dmp", SearchOption.AllDirectories);
Assert.ContainsSingle(dumpFiles, $"Expected single dump file. Found: {Environment.NewLine}{string.Join(Environment.NewLine, dumpFiles)}{Environment.NewLine}{testResult}");
}

[TestMethod]
Expand Down
Loading