From 3287fba28f61d9167bcb342a5447aec0ad45cacd Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 7 Jan 2019 15:37:53 +1300 Subject: [PATCH] Don't timeout in testing task extensions when debugger is attached (dotnet/extensions#903) \n\nCommit migrated from https://github.com/dotnet/extensions/commit/24c84a5b1db0fca3cfcc54eed3f4f94c6670a709 --- src/Testing/src/TaskExtensions.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Testing/src/TaskExtensions.cs b/src/Testing/src/TaskExtensions.cs index 83130aeae4..f99bf7361a 100644 --- a/src/Testing/src/TaskExtensions.cs +++ b/src/Testing/src/TaskExtensions.cs @@ -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 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) { 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;