Skip to content

Commit 3fb64f9

Browse files
Refactor property-based tests
Apply recommendations/fixes suggested by Copilot in #2830.
1 parent 156a9bb commit 3fb64f9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Polly.Core/Retry/RetryHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static TimeSpan ApplyJitter(TimeSpan delay, Func<double> randomizer)
5454

5555
return TimeSpan.FromMilliseconds(newDelay);
5656
}
57-
#pragma warning disable IDE0047 // Remove unnecessary parentheses which offer less mental gymnastics
57+
#pragma warning restore IDE0047 // Remove unnecessary parentheses which offer less mental gymnastics
5858

5959
/// <summary>
6060
/// Generates sleep durations in an exponentially backing-off, jittered manner, making sure to mitigate any correlations.

test/Polly.Core.Tests/Retry/RetryHelperTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,13 @@ public void ExponentialWithJitter_EnsureRandomness()
267267
[FsCheck.Xunit.Property(Arbitrary = [typeof(Arbitraries)], MaxTest = 10_000)]
268268
public void ApplyJitter_Meets_Specification(TimeSpan value)
269269
{
270-
var delta = value / 2;
270+
var delta = value / 4;
271271
var floor = value - delta;
272272
var ceiling = value + delta;
273273

274274
var actual = RetryHelper.ApplyJitter(value, RandomUtil.NextDouble);
275275

276-
actual.ShouldBeGreaterThan(floor);
276+
actual.ShouldBeGreaterThanOrEqualTo(floor);
277277
actual.ShouldBeLessThanOrEqualTo(ceiling);
278278
}
279279

@@ -283,13 +283,13 @@ public void DecorrelatedJitterBackoffV2_Meets_Specification(TimeSpan value, int
283283
var rawCeiling = value.Ticks * Math.Pow(2, attempt) * 4;
284284
var clamped = (long)Math.Clamp(rawCeiling, value.Ticks, TimeSpan.MaxValue.Ticks);
285285

286-
var floor = value;
286+
var floor = TimeSpan.Zero;
287287
var ceiling = TimeSpan.FromTicks(clamped - 1);
288288

289289
var _ = default(double);
290290
var actual = RetryHelper.DecorrelatedJitterBackoffV2(attempt, value, ref _, RandomUtil.NextDouble);
291291

292-
actual.ShouldBeGreaterThan(floor);
292+
actual.ShouldBeGreaterThanOrEqualTo(floor);
293293
actual.ShouldBeLessThanOrEqualTo(ceiling);
294294
}
295295
#endif
@@ -318,7 +318,7 @@ public static class Arbitraries
318318
public static Arbitrary<int> PositiveInteger()
319319
{
320320
var minimum = 1;
321-
var maximum = 2056;
321+
var maximum = 2048;
322322
var generator = Gen.Choose(minimum, maximum);
323323

324324
return Arb.From(generator);

0 commit comments

Comments
 (0)