Skip to content

Commit 681420a

Browse files
minor #39760 [HttpClient] Fix transient test with HttpClient jitter (jderusse)
This PR was merged into the 5.2 branch. Discussion ---------- [HttpClient] Fix transient test with HttpClient jitter | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | f- | License | MIT | Doc PR | - Fix transient test, when asserting jitter generates random delay Commits ------- 70fe66005a Fix transient test with HttpClient jitter
2 parents b26c551 + e6f16c4 commit 681420a

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Tests/Retry/GenericRetryStrategyTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,16 @@ public function provideDelay(): iterable
9393
public function testJitter()
9494
{
9595
$strategy = new GenericRetryStrategy([], 1000, 1, 0, 1);
96-
$belowHalf = 0;
97-
$aboveHalf = 0;
98-
for ($i = 0; $i < 20; ++$i) {
96+
$min = 2000;
97+
$max = 0;
98+
for ($i = 0; $i < 50; ++$i) {
9999
$delay = $strategy->getDelay($this->getContext(0, 'GET', 'http://example.com/', 200), null, null);
100-
if ($delay < 500) {
101-
++$belowHalf;
102-
} elseif ($delay > 1500) {
103-
++$aboveHalf;
104-
}
100+
$min = min($min, $delay);
101+
$max = max($max, $delay);
105102
}
106-
107-
$this->assertGreaterThanOrEqual(1, $belowHalf);
108-
$this->assertGreaterThanOrEqual(1, $aboveHalf);
103+
$this->assertGreaterThanOrEqual(1000, $max - $min);
104+
$this->assertGreaterThanOrEqual(1000, $max);
105+
$this->assertLessThanOrEqual(1000, $min);
109106
}
110107

111108
private function getContext($retryCount, $method, $url, $statusCode): AsyncContext

0 commit comments

Comments
 (0)