Skip to content

Commit 5829106

Browse files
committed
Fix flaky backoff test
1 parent 2cff983 commit 5829106

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/WebJobs.Script.Tests/UtilityTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public async Task DelayWithBackoffAsync_DelaysAsExpected()
6969
sw.Start();
7070
await Utility.DelayWithBackoffAsync(2, CancellationToken.None);
7171
sw.Stop();
72-
Assert.True(sw.Elapsed >= TimeSpan.FromSeconds(2), $"Expected sw.Elapsed >= TimeSpan.FromSeconds(2); Actual: {sw.Elapsed.TotalMilliseconds}");
72+
73+
// Workaround annoying test failures such as "Expected sw.Elapsed >= TimeSpan.FromSeconds(2); Actual: 1999.4092" by waiting slightly less than 2 seconds
74+
// Not sure what causes it, but either Task.Delay sometimes doesn't wait quite long enough or there is some clock skew.
75+
Assert.True(sw.Elapsed >= TimeSpan.FromMilliseconds(1990), $"Expected sw.Elapsed >= TimeSpan.FromMilliseconds(1990); Actual: {sw.Elapsed.TotalMilliseconds}");
7376
}
7477

7578
[Theory]

0 commit comments

Comments
 (0)