@@ -26,28 +26,43 @@ public async Task<int> RunAsync()
2626 {
2727 CancellationToken testApplicationCancellationToken = ServiceProvider . GetTestApplicationCancellationTokenSource ( ) . CancellationToken ;
2828
29- int exitCode ;
29+ int exitCode = ExitCodes . GenericFailure ;
3030 try
3131 {
3232 if ( PushOnlyProtocol is null || PushOnlyProtocol ? . IsServerMode == false )
3333 {
3434 exitCode = await RunTestAppAsync ( testApplicationCancellationToken ) ;
35+
36+ if ( testApplicationCancellationToken . IsCancellationRequested )
37+ {
38+ exitCode = ExitCodes . TestSessionAborted ;
39+ }
40+
3541 return exitCode ;
3642 }
3743
38- RoslynDebug . Assert ( PushOnlyProtocol is not null ) ;
44+ try
45+ {
46+ RoslynDebug . Assert ( PushOnlyProtocol is not null ) ;
3947
40- ITestApplicationModuleInfo testApplicationModuleInfo = serviceProvider . GetTestApplicationModuleInfo ( ) ;
41- bool isValidProtocol = await PushOnlyProtocol . IsCompatibleProtocolAsync ( GetHostType ( ) ) ;
48+ ITestApplicationModuleInfo testApplicationModuleInfo = serviceProvider . GetTestApplicationModuleInfo ( ) ;
49+ bool isValidProtocol = await PushOnlyProtocol . IsCompatibleProtocolAsync ( GetHostType ( ) ) ;
4250
43- exitCode = isValidProtocol
44- ? await RunTestAppAsync ( testApplicationCancellationToken )
45- : ExitCodes . IncompatibleProtocolVersion ;
51+ exitCode = isValidProtocol
52+ ? await RunTestAppAsync ( testApplicationCancellationToken )
53+ : ExitCodes . IncompatibleProtocolVersion ;
54+ }
55+ finally
56+ {
57+ if ( PushOnlyProtocol is not null )
58+ {
59+ await PushOnlyProtocol . OnExitAsync ( ) ;
60+ }
61+ }
4662 }
4763 catch ( OperationCanceledException ) when ( testApplicationCancellationToken . IsCancellationRequested )
4864 {
4965 // We do nothing we're canceling
50- exitCode = ExitCodes . TestSessionAborted ;
5166 }
5267 finally
5368 {
@@ -57,6 +72,11 @@ public async Task<int> RunAsync()
5772 await DisposeHelper . DisposeAsync ( ServiceProvider . GetTestApplicationCancellationTokenSource ( ) ) ;
5873 }
5974
75+ if ( testApplicationCancellationToken . IsCancellationRequested )
76+ {
77+ exitCode = ExitCodes . TestSessionAborted ;
78+ }
79+
6080 return exitCode ;
6181 }
6282
@@ -217,7 +237,8 @@ protected static async Task DisposeServiceProviderAsync(ServiceProvider serviceP
217237 // We need to ensure that we won't dispose special services till the shutdown
218238 if ( ! isProcessShutdown &&
219239 service is ITelemetryCollector or
220- ITestApplicationLifecycleCallbacks )
240+ ITestApplicationLifecycleCallbacks or
241+ IPushOnlyProtocol )
221242 {
222243 continue ;
223244 }
0 commit comments