From 637e7647b805ea9a1c3121beced3c6a726ca0e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 30 Jul 2024 13:31:02 +0200 Subject: [PATCH] Fix accessing PID in TestHostControllersTestHost --- .../Hosts/TestHostControllersTestHost.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs index 7efc4a78c9..bc431905b0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs +++ b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs @@ -205,15 +205,10 @@ protected override async Task 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) { @@ -221,6 +216,14 @@ protected override async Task InternalRunAsync() // 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}'");