Fix flaky backoff tests
Removes potential rounding errors by comparing two timespans
MODIFY
test/WebJobs.Script.Tests/UtilityTests.cs
test/WebJobs.Script.Tests/UtilityTests.cs
@@ -59,7 +59,7 @@ public async Task DelayWithBackoffAsync_Returns_WhenCancelled()
sw.Start();
await Utility.DelayWithBackoffAsync(20, tokenSource.Token);
sw.Stop();
- Assert.True(sw.ElapsedMilliseconds < 1000, $"Expected sw.ElapsedMilliseconds < 1000; Actual: {sw.ElapsedMilliseconds}");
+ Assert.True(sw.Elapsed < TimeSpan.FromSeconds(2), $"Expected sw.Elapsed < TimeSpan.FromSeconds(2); Actual: {sw.Elapsed.TotalMilliseconds}");
}
[Fact]
@@ -69,7 +69,7 @@ public async Task DelayWithBackoffAsync_DelaysAsExpected()
sw.Start();
await Utility.DelayWithBackoffAsync(2, CancellationToken.None);
sw.Stop();
- Assert.True(sw.ElapsedMilliseconds >= 2000, $"Expected sw.ElapsedMilliseconds >= 2000; Actual: {sw.ElapsedMilliseconds}");
+ Assert.True(sw.Elapsed >= TimeSpan.FromSeconds(2), $"Expected sw.Elapsed >= TimeSpan.FromSeconds(2); Actual: {sw.Elapsed.TotalMilliseconds}");
}
[Theory]

Fix flaky backoff tests
- Removes potential rounding errors by comparing two timespans