Repository navigation
Labels
area/mtpMicrosoft.Testing.Platform core library.
Description
testfx/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs
Lines 133 to 154 in 0962dc3
| protected static async Task ExecuteRequestAsync(ProxyOutputDevice outputDevice, ITestSessionContext testSessionInfo, | |
| ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, TestHost.ClientInfo client) | |
| { | |
| CancellationToken testSessionCancellationToken = serviceProvider.GetTestSessionContext().CancellationToken; | |
| await DisplayBeforeSessionStartAsync(outputDevice, testSessionInfo, testSessionCancellationToken).ConfigureAwait(false); | |
| try | |
| { | |
| await NotifyTestSessionStartAsync(testSessionInfo.SessionId, baseMessageBus, serviceProvider, testSessionCancellationToken).ConfigureAwait(false); | |
| await serviceProvider.GetTestAdapterInvoker().ExecuteAsync(testFramework, client, testSessionCancellationToken).ConfigureAwait(false); | |
| await NotifyTestSessionEndAsync(testSessionInfo.SessionId, baseMessageBus, serviceProvider, testSessionCancellationToken).ConfigureAwait(false); | |
| } | |
| catch (OperationCanceledException) when (testSessionCancellationToken.IsCancellationRequested) | |
| { | |
| // Do nothing we're canceled | |
| } | |
| // We keep the display after session out of the OperationCanceledException catch because we want to notify the IPlatformOutputDevice | |
| // also in case of cancellation. Most likely it needs to notify users that the session was canceled. | |
| await DisplayAfterSessionEndRunAsync(outputDevice, testSessionInfo, testSessionCancellationToken).ConfigureAwait(false); | |
| } |
We always call DisplayAfterSessionEndRunAsync at the end, regardless of whether or not we are canceled. But then we pass testSessionCancellationToken. That feels suspicious to me.
The comment says:
// We keep the display after session out of the OperationCanceledException catch because we want to notify the IPlatformOutputDevice
// also in case of cancellation. Most likely it needs to notify users that the session was canceled.
But in that case shouldn't we pass CancellationToken.None to explicitly state that we want the work to be done even in case of cancellation?
Activity