Fix transient test with HttpClient jitter
This commit is contained in:
parent
7e28ffa6a1
commit
70fe66005a
@ -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
|
||||||
|
Reference in New Issue
Block a user