Skip to content

Commit

Permalink
Standardize OCE and AggregateException handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 26, 2024
1 parent 52585b0 commit 3da2c4f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Adapter/MSTest.TestAdapter/Helpers/FixtureMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ internal static class FixtureMethodRunner
action();
return null;
}
catch (OperationCanceledException)
catch (Exception ex) when
((ex is OperationCanceledException oce && oce.CancellationToken == cancellationTokenSource.Token)
|| (ex is AggregateException aggregateEx && aggregateEx.InnerExceptions.OfType<TaskCanceledException>().Any()))
{
// Ideally we would like to check that the token of the exception matches cancellationTokenSource but TestContext
// instances are not well defined so we have to handle the exception entirely.
Expand Down Expand Up @@ -156,7 +158,7 @@ internal static class FixtureMethodRunner
timeout));
}
catch (Exception ex) when
(ex is OperationCanceledException
((ex is OperationCanceledException oce && oce.CancellationToken == cancellationTokenSource.Token)
|| (ex is AggregateException aggregateEx && aggregateEx.InnerExceptions.OfType<TaskCanceledException>().Any()))
{
return new(
Expand Down Expand Up @@ -220,10 +222,7 @@ internal static class FixtureMethodRunner
timeout));
}
catch (Exception ex) when

// This exception occurs when the cancellation happens before the task is actually started.
((ex is TaskCanceledException tce && tce.CancellationToken == cancellationTokenSource.Token)
|| (ex is OperationCanceledException oce && oce.CancellationToken == cancellationTokenSource.Token)
((ex is OperationCanceledException oce && oce.CancellationToken == cancellationTokenSource.Token)
|| (ex is AggregateException aggregateEx && aggregateEx.InnerExceptions.OfType<TaskCanceledException>().Any()))
{
return new(
Expand Down

0 comments on commit 3da2c4f

Please sign in to comment.