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()
{
$strategy = new GenericRetryStrategy([], 1000, 1, 0, 1);
$belowHalf = 0;
$aboveHalf = 0;
for ($i = 0; $i < 20; ++$i) {
$min = 2000;
$max = 0;
for ($i = 0; $i < 50; ++$i) {
$delay = $strategy->getDelay($this->getContext(0, 'GET', 'http://example.com/', 200), null, null);
if ($delay < 500) {
++$belowHalf;
} elseif ($delay > 1500) {
++$aboveHalf;
}
$min = min($min, $delay);
$max = max($max, $delay);
}
$this->assertGreaterThanOrEqual(1, $belowHalf);
$this->assertGreaterThanOrEqual(1, $aboveHalf);
$this->assertGreaterThanOrEqual(1000, $max - $min);
$this->assertGreaterThanOrEqual(1000, $max);
$this->assertLessThanOrEqual(1000, $min);
}
private function getContext($retryCount, $method, $url, $statusCode): AsyncContext