Skip to content

Commit f2af78c

Browse files
committed
Flaky test investigation
1 parent a9e46d6 commit f2af78c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Adapter/MSTest.TestAdapter/Helpers/FixtureMethodRunner.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Threading;
5+
46
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
57
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
68
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
@@ -125,7 +127,7 @@ internal static class FixtureMethodRunner
125127
Action action, CancellationTokenSource cancellationTokenSource, int timeout, MethodInfo methodInfo,
126128
IExecutionContextScope executionContextScope, string methodCanceledMessageFormat, string methodTimedOutMessageFormat)
127129
{
128-
Exception? realException = null;
130+
Exception? realException = null;
129131
Task? executionTask;
130132
try
131133
{
@@ -174,8 +176,15 @@ internal static class FixtureMethodRunner
174176
UnitTestOutcome.Timeout,
175177
string.Format(CultureInfo.InvariantCulture, methodCanceledMessageFormat, methodInfo.DeclaringType!.FullName, methodInfo.Name));
176178
}
177-
catch (Exception)
179+
catch (Exception ex)
178180
{
181+
if (ex is AggregateException aggregateEx && aggregateEx.InnerExceptions.OfType<TaskCanceledException>().Any(tce => tce.CancellationToken == cancellationTokenSource.Token))
182+
{
183+
return new(
184+
UnitTestOutcome.Timeout,
185+
"Are we going to hit this??");
186+
}
187+
179188
// We throw the real exception to have the original stack trace to elaborate up the chain.
180189
if (realException is not null)
181190
{

0 commit comments

Comments
 (0)