Don't timeout in testing task extensions when debugger is attached (dotnet/extensions#903)

\n\nCommit migrated from 24c84a5b1d
This commit is contained in:
James Newton-King 2019-01-07 15:37:53 +13:00 committed by GitHub
parent bdc2ea81c0
commit 3287fba28f
1 changed files with 9 additions and 7 deletions

View File

@ -1,7 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
@ -12,10 +13,11 @@ namespace Microsoft.AspNetCore.Testing
{
public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = default(int))
[CallerLineNumber] int lineNumber = default)
{
// Don't create a timer if the task is already completed
if (task.IsCompleted)
// or the debugger is attached
if (task.IsCompleted || Debugger.IsAttached)
{
return await task;
}
@ -28,17 +30,17 @@ namespace Microsoft.AspNetCore.Testing
}
else
{
throw new TimeoutException(
CreateMessage(timeout, filePath, lineNumber));
throw new TimeoutException(CreateMessage(timeout, filePath, lineNumber));
}
}
public static async Task TimeoutAfter(this Task task, TimeSpan timeout,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = default(int))
[CallerLineNumber] int lineNumber = default)
{
// Don't create a timer if the task is already completed
if (task.IsCompleted)
// or the debugger is attached
if (task.IsCompleted || Debugger.IsAttached)
{
await task;
return;