Fix transient test with HttpClient jitter

This commit is contained in:
Jérémy Derussé 2021-01-07 23:51:21 +01:00
parent 7e28ffa6a1
commit 70fe66005a
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2

View File

@ -93,19 +93,16 @@ class GenericRetryStrategyTest extends TestCase
public function testJitter() public function testJitter()
{ {
$strategy = new GenericRetryStrategy([], 1000, 1, 0, 1); $strategy = new GenericRetryStrategy([], 1000, 1, 0, 1);
$belowHalf = 0; $min = 2000;
$aboveHalf = 0; $max = 0;
for ($i = 0; $i < 20; ++$i) { for ($i = 0; $i < 50; ++$i) {
$delay = $strategy->getDelay($this->getContext(0, 'GET', 'http://example.com/', 200), null, null); $delay = $strategy->getDelay($this->getContext(0, 'GET', 'http://example.com/', 200), null, null);
if ($delay < 500) { $min = min($min, $delay);
++$belowHalf; $max = max($max, $delay);
} elseif ($delay > 1500) {
++$aboveHalf;
}
} }
$this->assertGreaterThanOrEqual(1000, $max - $min);
$this->assertGreaterThanOrEqual(1, $belowHalf); $this->assertGreaterThanOrEqual(1000, $max);
$this->assertGreaterThanOrEqual(1, $aboveHalf); $this->assertLessThanOrEqual(1000, $min);
} }
private function getContext($retryCount, $method, $url, $statusCode): AsyncContext private function getContext($retryCount, $method, $url, $statusCode): AsyncContext