diff --git a/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs b/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs index 4a515f88e5..474ed0fc71 100644 --- a/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs +++ b/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs @@ -1048,8 +1048,7 @@ public void Should_honour_cancellation_immediately_during_wait_phase_of_waitandr int attemptsInvoked = 0; Action onExecute = () => attemptsInvoked++; - Stopwatch watch = new Stopwatch(); - watch.Start(); + var watch = Stopwatch.StartNew(); PolicyExtensions.ExceptionAndOrCancellationScenario scenario = new PolicyExtensions.ExceptionAndOrCancellationScenario { diff --git a/test/Polly.Specs/Timeout/TimeoutSpecs.cs b/test/Polly.Specs/Timeout/TimeoutSpecs.cs index 74886f699e..1ac980b4eb 100644 --- a/test/Polly.Specs/Timeout/TimeoutSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutSpecs.cs @@ -266,14 +266,12 @@ public void Should_not_throw_when_timeout_is_greater_than_execution_duration__pe [Fact] public void Should_throw_timeout_after_correct_duration__pessimistic() { - Stopwatch watch = new Stopwatch(); - TimeSpan timeout = TimeSpan.FromSeconds(1); var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic); TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. - watch.Start(); + var watch = Stopwatch.StartNew(); Should.Throw(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(10), CancellationToken))); watch.Stop(); @@ -410,15 +408,13 @@ public void Should_not_throw_when_timeout_is_greater_than_execution_duration__op [Fact] public void Should_throw_timeout_after_correct_duration__optimistic() { - Stopwatch watch = new Stopwatch(); - TimeSpan timeout = TimeSpan.FromSeconds(1); var policy = Policy.Timeout(timeout); var userCancellationToken = CancellationToken; TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. - watch.Start(); + var watch = Stopwatch.StartNew(); // Delegate observes cancellation token, so permitting optimistic cancellation. Should.Throw(() => policy.Execute(ct => SystemClock.Sleep(TimeSpan.FromSeconds(10), ct), userCancellationToken));