Skip to content

Commit 33735ad

Browse files
authored
Don't timeout in testing task extensions when debugger is attached (dotnet/extensions#903)
\n\nCommit migrated from dotnet/extensions@24c84a5
1 parent 73224a7 commit 33735ad

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/TestingUtils/Microsoft.AspNetCore.Testing/src/TaskExtensions.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Diagnostics;
56
using System.Runtime.CompilerServices;
67
using System.Threading;
78
using System.Threading.Tasks;
@@ -12,10 +13,11 @@ public static class TaskExtensions
1213
{
1314
public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
1415
[CallerFilePath] string filePath = null,
15-
[CallerLineNumber] int lineNumber = default(int))
16+
[CallerLineNumber] int lineNumber = default)
1617
{
1718
// Don't create a timer if the task is already completed
18-
if (task.IsCompleted)
19+
// or the debugger is attached
20+
if (task.IsCompleted || Debugger.IsAttached)
1921
{
2022
return await task;
2123
}
@@ -28,17 +30,17 @@ public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
2830
}
2931
else
3032
{
31-
throw new TimeoutException(
32-
CreateMessage(timeout, filePath, lineNumber));
33+
throw new TimeoutException(CreateMessage(timeout, filePath, lineNumber));
3334
}
3435
}
3536

3637
public static async Task TimeoutAfter(this Task task, TimeSpan timeout,
3738
[CallerFilePath] string filePath = null,
38-
[CallerLineNumber] int lineNumber = default(int))
39+
[CallerLineNumber] int lineNumber = default)
3940
{
4041
// Don't create a timer if the task is already completed
41-
if (task.IsCompleted)
42+
// or the debugger is attached
43+
if (task.IsCompleted || Debugger.IsAttached)
4244
{
4345
await task;
4446
return;

0 commit comments

Comments
 (0)