@@ -18,21 +18,24 @@ internal sealed class WebTestSessionExecutor : ITestSessionExecutor
1818 private readonly IMonitorLayoutService _monitorLayoutService ;
1919 private readonly AppSettings _settings ;
2020 private readonly ILogger < WebTestSessionExecutor > _logger ;
21+ private readonly IProcessLifecycleManager _processLifecycle ;
2122
2223 public WebTestSessionExecutor (
2324 ICodetracerLauncher launcher ,
2425 ICtHostLauncher hostLauncher ,
2526 IPortAllocator portAllocator ,
2627 IMonitorLayoutService monitorLayoutService ,
2728 IOptions < AppSettings > settings ,
28- ILogger < WebTestSessionExecutor > logger )
29+ ILogger < WebTestSessionExecutor > logger ,
30+ IProcessLifecycleManager processLifecycle )
2931 {
3032 _launcher = launcher ;
3133 _hostLauncher = hostLauncher ;
3234 _portAllocator = portAllocator ;
3335 _monitorLayoutService = monitorLayoutService ;
3436 _settings = settings . Value ;
3537 _logger = logger ;
38+ _processLifecycle = processLifecycle ;
3639 }
3740
3841 public TestMode Mode => TestMode . Web ;
@@ -53,18 +56,26 @@ public async Task ExecuteAsync(TestPlanEntry entry, CancellationToken cancellati
5356
5457 var label = $ "{ entry . Scenario . Id } -{ entry . Mode } ";
5558 var hostProcess = _hostLauncher . StartHostProcess ( httpPort , backendPort , frontendPort , tracePath , label ) ;
56- await using var session = await CreateWebSessionAsync ( hostProcess , httpPort , entry , cancellationToken ) ;
59+ _processLifecycle . RegisterProcess ( hostProcess , $ "ct-host:{ label } ") ;
60+ await using var session = await CreateWebSessionAsync ( hostProcess , httpPort , entry , label , cancellationToken ) ;
61+ try
62+ {
63+
64+ if ( entry . Scenario . DelaySeconds > 0 )
65+ {
66+ await Task . Delay ( TimeSpan . FromSeconds ( entry . Scenario . DelaySeconds ) , cancellationToken ) ;
67+ }
5768
58- if ( entry . Scenario . DelaySeconds > 0 )
69+ var context = new TestExecutionContext ( entry . Scenario , entry . Mode , session . Page , cancellationToken ) ;
70+ await entry . Test . Handler ( context ) ;
71+ }
72+ finally
5973 {
60- await Task . Delay ( TimeSpan . FromSeconds ( entry . Scenario . DelaySeconds ) , cancellationToken ) ;
74+ _processLifecycle . UnregisterProcess ( hostProcess . Id ) ;
6175 }
62-
63- var context = new TestExecutionContext ( entry . Scenario , entry . Mode , session . Page , cancellationToken ) ;
64- await entry . Test . Handler ( context ) ;
6576 }
6677
67- private async Task < WebTestSession > CreateWebSessionAsync ( Process hostProcess , int port , TestPlanEntry entry , CancellationToken cancellationToken )
78+ private async Task < WebTestSession > CreateWebSessionAsync ( Process hostProcess , int port , TestPlanEntry entry , string label , CancellationToken cancellationToken )
6879 {
6980 await _hostLauncher . WaitForServerAsync ( port , TimeSpan . FromSeconds ( _settings . Web . HostStartupTimeoutSeconds ) , entry . Scenario . Id , cancellationToken ) ;
7081
@@ -114,7 +125,7 @@ private async Task<WebTestSession> CreateWebSessionAsync(Process hostProcess, in
114125 _logger . LogDebug ( "[{Scenario}] Window resize script could not adjust browser bounds." , entry . Scenario . Id ) ;
115126 }
116127
117- return new WebTestSession ( hostProcess , playwright , browser , context , page ) ;
128+ return new WebTestSession ( hostProcess , playwright , browser , context , page , _processLifecycle , $ "ct-host: { label } " ) ;
118129 }
119130
120131}
0 commit comments