Skip to content

Commit

Permalink
Fix accessing PID in TestHostControllersTestHost
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Aug 2, 2024
1 parent 0044362 commit 637e764
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,25 @@ protected override async Task<int> InternalRunAsync()
await _logger.LogDebugAsync($"Starting test host process");
using IProcess testHostProcess = process.Start(processStartInfo);

testHostProcess.Exited += (sender, e) =>
{
var processExited = sender as Process;
_logger.LogDebug($"Test host process exited, PID: '{processExited?.Id}'");
};

int? testHostProcessId = null;
try
{
await _logger.LogDebugAsync($"Started test host process '{testHostProcess.Id}' HasExited: {testHostProcess.HasExited}");
testHostProcessId = testHostProcess.Id;
}
catch (InvalidOperationException) when (testHostProcess.HasExited)
{
// Access PID can throw InvalidOperationException if the process has already exited:
// System.InvalidOperationException: No process is associated with this object.
}

testHostProcess.Exited += (sender, e) =>
{
var processExited = sender as Process;
_logger.LogDebug($"Test host process exited, PID: '{testHostProcessId}'");
};

await _logger.LogDebugAsync($"Started test host process '{testHostProcessId}' HasExited: {testHostProcess.HasExited}");

string? seconds = configuration[PlatformConfigurationConstants.PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds];
int timeoutSeconds = seconds is null ? TimeoutHelper.DefaultHangTimeoutSeconds : int.Parse(seconds, CultureInfo.InvariantCulture);
await _logger.LogDebugAsync($"Setting PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds '{timeoutSeconds}'");
Expand Down

0 comments on commit 637e764

Please sign in to comment.