55using Microsoft . Testing . Platform . Extensions ;
66using Microsoft . Testing . Platform . Extensions . Messages ;
77using Microsoft . Testing . Platform . Extensions . OutputDevice ;
8- using Microsoft . Testing . Platform . Extensions . TestHost ;
98using Microsoft . Testing . Platform . Helpers ;
109using Microsoft . Testing . Platform . Logging ;
1110using Microsoft . Testing . Platform . OutputDevice . Terminal ;
@@ -22,7 +21,6 @@ namespace Microsoft.Testing.Platform.OutputDevice;
2221internal sealed partial class TerminalOutputDevice : IHotReloadPlatformOutputDevice ,
2322 IDataConsumer ,
2423 IOutputDeviceDataProducer ,
25- ITestSessionLifetimeHandler ,
2624 IDisposable ,
2725 IAsyncInitializableExtension
2826{
@@ -55,11 +53,11 @@ internal sealed partial class TerminalOutputDevice : IHotReloadPlatformOutputDev
5553 private readonly string _assemblyName ;
5654
5755 private TerminalTestReporter ? _terminalTestReporter ;
58- private bool _firstCallTo_OnSessionStartingAsync = true ;
5956 private bool _bannerDisplayed ;
6057 private bool _isListTests ;
6158 private bool _isServerMode ;
6259 private ILogger ? _logger ;
60+ private TestProcessRole ? _processRole ;
6361
6462 public TerminalOutputDevice (
6563 IConsole console ,
@@ -325,36 +323,14 @@ private async Task DisplayAfterSessionEndRunInternalAsync()
325323
326324 using ( await _asyncMonitor . LockAsync ( TimeoutHelper . DefaultHangTimeSpanTimeout ) . ConfigureAwait ( false ) )
327325 {
328- if ( ! _firstCallTo_OnSessionStartingAsync )
326+ if ( _processRole == TestProcessRole . TestHost )
329327 {
330328 _terminalTestReporter . AssemblyRunCompleted ( ) ;
331329 _terminalTestReporter . TestExecutionCompleted ( _clock . UtcNow ) ;
332330 }
333331 }
334332 }
335333
336- public Task OnTestSessionFinishingAsync ( ITestSessionContext testSessionContext ) => Task . CompletedTask ;
337-
338- public Task OnTestSessionStartingAsync ( ITestSessionContext testSessionContext )
339- {
340- CancellationToken cancellationToken = testSessionContext . CancellationToken ;
341- cancellationToken . ThrowIfCancellationRequested ( ) ;
342- if ( _isServerMode )
343- {
344- return Task . CompletedTask ;
345- }
346-
347- // We implement IDataConsumerService and IOutputDisplayService.
348- // So the engine is calling us before as IDataConsumerService and after as IOutputDisplayService.
349- // The engine look for the ITestSessionLifetimeHandler in both case and call it.
350- if ( _firstCallTo_OnSessionStartingAsync )
351- {
352- _firstCallTo_OnSessionStartingAsync = false ;
353- }
354-
355- return Task . CompletedTask ;
356- }
357-
358334 /// <summary>
359335 /// Displays provided data through IConsole, which is typically System.Console.
360336 /// </summary>
@@ -416,9 +392,8 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
416392
417393 foreach ( FileArtifactProperty artifact in testNodeStateChanged . TestNode . Properties . OfType < FileArtifactProperty > ( ) )
418394 {
419- bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync ;
420395 _terminalTestReporter . ArtifactAdded (
421- isOutOfProcessArtifact ,
396+ outOfProcess : _processRole != TestProcessRole . TestHost ,
422397 testNodeStateChanged . TestNode . DisplayName ,
423398 artifact . FileInfo . FullName ) ;
424399 }
@@ -532,19 +507,17 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
532507
533508 case SessionFileArtifact artifact :
534509 {
535- bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync ;
536510 _terminalTestReporter . ArtifactAdded (
537- isOutOfProcessArtifact ,
511+ outOfProcess : _processRole != TestProcessRole . TestHost ,
538512 testName : null ,
539513 artifact . FileInfo . FullName ) ;
540514 }
541515
542516 break ;
543517 case FileArtifact artifact :
544518 {
545- bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync ;
546519 _terminalTestReporter . ArtifactAdded (
547- isOutOfProcessArtifact ,
520+ outOfProcess : _processRole != TestProcessRole . TestHost ,
548521 testName : null ,
549522 artifact . FileInfo . FullName ) ;
550523 }
@@ -560,6 +533,7 @@ public void Dispose()
560533
561534 public async Task HandleProcessRoleAsync ( TestProcessRole processRole , CancellationToken cancellationToken )
562535 {
536+ _processRole = processRole ;
563537 if ( processRole == TestProcessRole . TestHost )
564538 {
565539 await _policiesService . RegisterOnMaxFailedTestsCallbackAsync (
0 commit comments