Skip to content

Commit

Permalink
Fix RetryMiddleware default exponential delay (#2132)
Browse files Browse the repository at this point in the history
* Fix RetryMiddleware::exponentialDelay by making it return milliseconds

RetryMiddleware::exponentialDelay was being used as-is to set the delay option in the retry middleware. However, the option requires milliseconds and this method was returning seconds.

* Fix RetryMiddleware::exponentialDelay by making it return milliseconds

RetryMiddleware::exponentialDelay was being used as-is to set the delay option in the retry middleware. However, the option requires milliseconds and this method was returning seconds.

* Fix exponentialDelay int casting

* Added comment
  • Loading branch information
dluces authored and Nyholm committed Dec 7, 2019
1 parent 8d1a5f2 commit 1293c1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/RetryMiddleware.php
Expand Up @@ -47,11 +47,11 @@ public function __construct(
*
* @param int $retries
*
* @return int
* @return int milliseconds.
*/
public static function exponentialDelay($retries)
{
return (int) pow(2, $retries - 1);
return (int) pow(2, $retries - 1) * 1000;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/RetryMiddlewareTest.php
Expand Up @@ -73,9 +73,9 @@ public function testCanRetryExceptions()
public function testBackoffCalculateDelay()
{
self::assertSame(0, RetryMiddleware::exponentialDelay(0));
self::assertSame(1, RetryMiddleware::exponentialDelay(1));
self::assertSame(2, RetryMiddleware::exponentialDelay(2));
self::assertSame(4, RetryMiddleware::exponentialDelay(3));
self::assertSame(8, RetryMiddleware::exponentialDelay(4));
self::assertSame(1000, RetryMiddleware::exponentialDelay(1));
self::assertSame(2000, RetryMiddleware::exponentialDelay(2));
self::assertSame(4000, RetryMiddleware::exponentialDelay(3));
self::assertSame(8000, RetryMiddleware::exponentialDelay(4));
}
}

0 comments on commit 1293c1b

Please sign in to comment.