From ae908fec2549ae2e901124794faf2f2233461ec8 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 22 Oct 2020 22:06:04 -0500 Subject: [PATCH] Increase Hosting tests timeout (#43695) * Increase Hosting tests timeout There are some environments (checked CoreCLR, no tiered compilation) where the current timeout is insufficient. Increasing the timeout so the tests don't fail in these environments. Fix #43389 --- .../tests/UnitTests/HostTests.cs | 4 ++-- .../tests/UnitTests/Internal/HostTests.cs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostTests.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostTests.cs index 8d8704d..5329b68 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostTests.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostTests.cs @@ -197,8 +197,8 @@ namespace Microsoft.Extensions.Hosting.Tests { configReloadedCancelTokenSource.Cancel(); }, null); - // Wait for up to 10 seconds, if config reloads at any time, cancel the wait. - await Task.WhenAny(Task.Delay(10000, configReloadedCancelToken)); // Task.WhenAny ignores the task throwing on cancellation. + // Wait for up to 1 minute, if config reloads at any time, cancel the wait. + await Task.WhenAny(Task.Delay(TimeSpan.FromMinutes(1), configReloadedCancelToken)); // Task.WhenAny ignores the task throwing on cancellation. Assert.NotEqual(dynamicConfigMessage1, dynamicConfigMessage2); // Messages are different. Assert.Equal(dynamicConfigMessage2, config["Hello"]); // Config DID reload from disk } diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs index d8c71cd..6ea731c 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Tracing; using System.Linq; using System.Threading; @@ -1223,7 +1224,7 @@ namespace Microsoft.Extensions.Hosting.Internal /// (after an await), the exception gets logged correctly. /// [Fact] - public void BackgroundServiceAsyncExceptionGetsLogged() + public async Task BackgroundServiceAsyncExceptionGetsLogged() { using TestEventListener listener = new TestEventListener(); @@ -1238,8 +1239,9 @@ namespace Microsoft.Extensions.Hosting.Internal }) .Start(); - // give the background service 5 seconds to log the failure - Task timeout = Task.Delay(new TimeSpan(0, 0, 5)); + // give the background service 1 minute to log the failure + TimeSpan timeout = TimeSpan.FromMinutes(1); + Stopwatch sw = Stopwatch.StartNew(); while (true) { @@ -1251,10 +1253,8 @@ namespace Microsoft.Extensions.Hosting.Internal break; } - if (timeout.IsCompleted) - { - Assert.True(false, "'BackgroundService failed' did not get logged"); - } + Assert.InRange(sw.Elapsed, TimeSpan.Zero, timeout); + await Task.Delay(TimeSpan.FromMilliseconds(30)); } } -- 2.7.4