Skip to content

Commit

Permalink
Rename getBackoffPeriod to calculateBackoffPeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Wright committed Mar 14, 2017
1 parent 059e96d commit a363f79
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/RetryStrategy/ExponentialBackoffStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($maxRetries = 2, $firstFastRetry = false, $multiplie
* @param int $retryCount
* @return int
*/
public function getBackoffPeriod($retryCount)
public function calculateBackoffPeriod($retryCount)
{
$offset = $this->firstFastRetry ? $this->multiplier : 0;
$backoff = $this->minBackoff + rand(0, $this->multiplier * pow(2, $retryCount) - $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/RetryStrategy/RetryStrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public function shouldRetry($retryCount);
* @param int $retryCount
* @return int
*/
public function getBackoffPeriod($retryCount);
public function calculateBackoffPeriod($retryCount);
}
2 changes: 1 addition & 1 deletion src/TransientFaultHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function execute(callable $task)
break;
}

$backoffPeriod = $this->retryStrategy->getBackoffPeriod($retryCount);
$backoffPeriod = $this->retryStrategy->calculateBackoffPeriod($retryCount);
$retryCount++;

if ($this->logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExponentialBackoffStrategyTest extends TestCase
public function testBackoffPeriodIsAboveMinimum($maxRetries, $firstFastRetry, $multiplier, $minBackoff, $maxBackoff, $retryCount)
{
$strategy = new ExponentialBackoffStrategy($maxRetries, $firstFastRetry, $multiplier, $minBackoff, $maxBackoff);
$this->assertGreaterThanOrEqual($minBackoff, $strategy->getBackoffPeriod($retryCount));
$this->assertGreaterThanOrEqual($minBackoff, $strategy->calculateBackoffPeriod($retryCount));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/TransientFaultHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testDoesNotRetryAfterSuccess(array $isTransientReturnValues, $ex

// Mock the retry strategy
$this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0);

// Mock the Sleep class
$this->sleep->shouldReceive('milliSleep');
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testDoesNotRetryAfterNonTransientException()

// Mock the retry strategy
$this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0);

// Mock the Sleep class
$this->sleep->shouldReceive('milliSleep');
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testTransientExceptionsIgnored()

// Mock the retry strategy
$this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0);

// Mock the Sleep class
$this->sleep->shouldReceive('milliSleep');
Expand Down Expand Up @@ -189,7 +189,7 @@ public function testRetriesAccordingToRetryStrategy()

// Mock the retry strategy
$this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true, true, true, false);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0);

// Mock the Sleep class
$this->sleep->shouldReceive('milliSleep');
Expand Down Expand Up @@ -229,7 +229,7 @@ public function testSleepsAccordingToRetryStrategy(array $backoffPeriods, array
// Mock the retry strategy
$expectation = $this->retryStrategy->shouldReceive('shouldRetry');
call_user_func_array([$expectation, 'andReturn'], $shouldRetryReturnValues);
$expectation = $this->retryStrategy->shouldReceive('getBackoffPeriod');
$expectation = $this->retryStrategy->shouldReceive('calculateBackoffPeriod');
call_user_func_array([$expectation, 'andReturn'], $backoffPeriods);

// Mock the Sleep class
Expand Down Expand Up @@ -272,8 +272,8 @@ public function testRetryCountIsIncremented()

// Mock the retry strategy
$this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true, true, false);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->with(0)->andReturn(0);
$this->retryStrategy->shouldReceive('getBackoffPeriod')->with(1)->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->with(0)->andReturn(0);
$this->retryStrategy->shouldReceive('calculateBackoffPeriod')->with(1)->andReturn(0);

// Mock the Sleep class
$this->sleep->shouldReceive('milliSleep');
Expand Down

0 comments on commit a363f79

Please sign in to comment.