@@ -69,7 +69,6 @@ protected override async Task<int> InternalRunAsync()
69
69
IEnvironment environment = ServiceProvider . GetEnvironment ( ) ;
70
70
IProcessHandler process = ServiceProvider . GetProcessHandler ( ) ;
71
71
ITestApplicationModuleInfo testApplicationModuleInfo = ServiceProvider . GetTestApplicationModuleInfo ( ) ;
72
- ExecutableInfo executableInfo = testApplicationModuleInfo . GetCurrentExecutableInfo ( ) ;
73
72
ITelemetryCollector telemetry = ServiceProvider . GetTelemetryCollector ( ) ;
74
73
ITelemetryInformation telemetryInformation = ServiceProvider . GetTelemetryInformation ( ) ;
75
74
string ? extensionInformation = null ;
@@ -80,6 +79,10 @@ protected override async Task<int> InternalRunAsync()
80
79
using IProcess currentProcess = process . GetCurrentProcess ( ) ;
81
80
int currentPID = currentProcess . Id ;
82
81
string processIdString = currentPID . ToString ( CultureInfo . InvariantCulture ) ;
82
+
83
+ ExecutableInfo executableInfo = testApplicationModuleInfo . GetCurrentExecutableInfo ( ) ;
84
+ await _logger . LogDebugAsync ( $ "Test host controller process info: { executableInfo } ") ;
85
+
83
86
List < string > partialCommandLine =
84
87
[
85
88
.. executableInfo . Arguments ,
@@ -223,7 +226,7 @@ protected override async Task<int> InternalRunAsync()
223
226
string testHostProcessStartupTime = _clock . UtcNow . ToString ( "HH:mm:ss.fff" , CultureInfo . InvariantCulture ) ;
224
227
processStartInfo . EnvironmentVariables . Add ( $ "{ EnvironmentVariableConstants . TESTINGPLATFORM_TESTHOSTCONTROLLER_TESTHOSTPROCESSSTARTTIME } _{ currentPID } ", testHostProcessStartupTime ) ;
225
228
await _logger . LogDebugAsync ( $ "{ EnvironmentVariableConstants . TESTINGPLATFORM_TESTHOSTCONTROLLER_TESTHOSTPROCESSSTARTTIME } _{ currentPID } '{ testHostProcessStartupTime } '") ;
226
- await _logger . LogDebugAsync ( "Starting test host process" ) ;
229
+ await _logger . LogDebugAsync ( $ "Starting test host process ' { processStartInfo . FileName } ' with args ' { processStartInfo . Arguments } ' ") ;
227
230
using IProcess testHostProcess = process . Start ( processStartInfo ) ;
228
231
229
232
int ? testHostProcessId = null ;
@@ -242,59 +245,68 @@ protected override async Task<int> InternalRunAsync()
242
245
243
246
await _logger . LogDebugAsync ( $ "Started test host process '{ testHostProcessId } ' HasExited: { testHostProcess . HasExited } ") ;
244
247
245
- string ? seconds = configuration [ PlatformConfigurationConstants . PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds ] ;
246
- int timeoutSeconds = seconds is null ? TimeoutHelper . DefaultHangTimeoutSeconds : int . Parse ( seconds , CultureInfo . InvariantCulture ) ;
247
- await _logger . LogDebugAsync ( $ "Setting PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds '{ timeoutSeconds } '") ;
248
-
249
- // Wait for the test host controller to connect
250
- using ( CancellationTokenSource timeout = new ( TimeSpan . FromSeconds ( timeoutSeconds ) ) )
251
- using ( var linkedToken = CancellationTokenSource . CreateLinkedTokenSource ( timeout . Token , abortRun ) )
248
+ if ( testHostProcess . HasExited || testHostProcessId is null )
252
249
{
253
- await _logger . LogDebugAsync ( "Wait connection from the test host process" ) ;
254
- await testHostControllerIpc . WaitConnectionAsync ( linkedToken . Token ) ;
250
+ await _logger . LogDebugAsync ( "Test host process exited prematurely" ) ;
255
251
}
256
-
257
- // Wait for the test host controller to send the PID of the test host process
258
- using ( CancellationTokenSource timeout = new ( TimeoutHelper . DefaultHangTimeSpanTimeout ) )
252
+ else
259
253
{
260
- _waitForPid . Wait ( timeout . Token ) ;
261
- }
254
+ string ? seconds = configuration [ PlatformConfigurationConstants . PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds ] ;
255
+ int timeoutSeconds = seconds is null ? TimeoutHelper . DefaultHangTimeoutSeconds : int . Parse ( seconds , CultureInfo . InvariantCulture ) ;
256
+ await _logger . LogDebugAsync ( $ "Setting PlatformTestHostControllersManagerSingleConnectionNamedPipeServerWaitConnectionTimeoutSeconds '{ timeoutSeconds } '") ;
262
257
263
- await _logger . LogDebugAsync ( "Fire OnTestHostProcessStartedAsync" ) ;
258
+ // Wait for the test host controller to connect
259
+ using ( CancellationTokenSource timeout = new ( TimeSpan . FromSeconds ( timeoutSeconds ) ) )
260
+ using ( var linkedToken = CancellationTokenSource . CreateLinkedTokenSource ( timeout . Token , abortRun ) )
261
+ {
262
+ await _logger . LogDebugAsync ( "Wait connection from the test host process" ) ;
263
+ await testHostControllerIpc . WaitConnectionAsync ( linkedToken . Token ) ;
264
+ }
264
265
265
- if ( _testHostPID is null )
266
- {
267
- throw ApplicationStateGuard . Unreachable ( ) ;
268
- }
266
+ // Wait for the test host controller to send the PID of the test host process
267
+ using ( CancellationTokenSource timeout = new ( TimeoutHelper . DefaultHangTimeSpanTimeout ) )
268
+ {
269
+ _waitForPid . Wait ( timeout . Token ) ;
270
+ }
269
271
270
- if ( _testHostsInformation . LifetimeHandlers . Length > 0 )
271
- {
272
- // We don't block the host during the 'OnTestHostProcessStartedAsync' by-design, if 'ITestHostProcessLifetimeHandler' extensions needs
273
- // to block the execution of the test host should add an in-process extension like an 'ITestApplicationLifecycleCallbacks' and
274
- // wait for a connection/signal to return.
275
- TestHostProcessInformation testHostProcessInformation = new ( _testHostPID . Value ) ;
276
- foreach ( ITestHostProcessLifetimeHandler lifetimeHandler in _testHostsInformation . LifetimeHandlers )
272
+ await _logger . LogDebugAsync ( "Fire OnTestHostProcessStartedAsync" ) ;
273
+
274
+ if ( _testHostPID is null )
277
275
{
278
- await lifetimeHandler . OnTestHostProcessStartedAsync ( testHostProcessInformation , abortRun ) ;
276
+ throw ApplicationStateGuard . Unreachable ( ) ;
277
+ }
278
+
279
+ if ( _testHostsInformation . LifetimeHandlers . Length > 0 )
280
+ {
281
+ // We don't block the host during the 'OnTestHostProcessStartedAsync' by-design, if 'ITestHostProcessLifetimeHandler' extensions needs
282
+ // to block the execution of the test host should add an in-process extension like an 'ITestApplicationLifecycleCallbacks' and
283
+ // wait for a connection/signal to return.
284
+ TestHostProcessInformation testHostProcessInformation = new ( _testHostPID . Value ) ;
285
+ foreach ( ITestHostProcessLifetimeHandler lifetimeHandler in _testHostsInformation . LifetimeHandlers )
286
+ {
287
+ await lifetimeHandler . OnTestHostProcessStartedAsync ( testHostProcessInformation , abortRun ) ;
288
+ }
279
289
}
280
- }
281
290
282
- await _logger . LogDebugAsync ( "Wait for test host process exit" ) ;
283
- await testHostProcess . WaitForExitAsync ( ) ;
291
+ await _logger . LogDebugAsync ( "Wait for test host process exit" ) ;
292
+ await testHostProcess . WaitForExitAsync ( ) ;
293
+ }
284
294
285
295
if ( _testHostsInformation . LifetimeHandlers . Length > 0 )
286
296
{
287
297
await _logger . LogDebugAsync ( $ "Fire OnTestHostProcessExitedAsync testHostGracefullyClosed: { _testHostGracefullyClosed } ") ;
288
298
var messageBusProxy = ( MessageBusProxy ) ServiceProvider . GetMessageBus ( ) ;
289
299
290
- ApplicationStateGuard . Ensure ( _testHostPID is not null ) ;
291
- TestHostProcessInformation testHostProcessInformation = new ( _testHostPID . Value , testHostProcess . ExitCode , _testHostGracefullyClosed ) ;
292
- foreach ( ITestHostProcessLifetimeHandler lifetimeHandler in _testHostsInformation . LifetimeHandlers )
300
+ if ( _testHostPID is not null )
293
301
{
294
- await lifetimeHandler . OnTestHostProcessExitedAsync ( testHostProcessInformation , abortRun ) ;
302
+ TestHostProcessInformation testHostProcessInformation = new ( _testHostPID . Value , testHostProcess . ExitCode , _testHostGracefullyClosed ) ;
303
+ foreach ( ITestHostProcessLifetimeHandler lifetimeHandler in _testHostsInformation . LifetimeHandlers )
304
+ {
305
+ await lifetimeHandler . OnTestHostProcessExitedAsync ( testHostProcessInformation , abortRun ) ;
295
306
296
- // OnTestHostProcess could produce information that needs to be handled by others.
297
- await messageBusProxy . DrainDataAsync ( ) ;
307
+ // OnTestHostProcess could produce information that needs to be handled by others.
308
+ await messageBusProxy . DrainDataAsync ( ) ;
309
+ }
298
310
}
299
311
300
312
// We disable after the drain because it's possible that the drain will produce more messages
0 commit comments