Increase Hosting tests timeout (#43695)
authorEric Erhardt <eric.erhardt@microsoft.com>
Fri, 23 Oct 2020 03:06:04 +0000 (22:06 -0500)
committerGitHub <noreply@github.com>
Fri, 23 Oct 2020 03:06:04 +0000 (22:06 -0500)
* 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

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostTests.cs
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs

index 8d8704d..5329b68 100644 (file)
@@ -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
         }
index d8c71cd..6ea731c 100644 (file)
@@ -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.
         /// </summary>
         [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));
             }
         }