{
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
}
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Threading;
/// (after an await), the exception gets logged correctly.
/// </summary>
[Fact]
- public void BackgroundServiceAsyncExceptionGetsLogged()
+ public async Task BackgroundServiceAsyncExceptionGetsLogged()
{
using TestEventListener listener = new TestEventListener();
})
.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)
{
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));
}
}