Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry attempts fixed. Exception throwing for the retry() method unified for all cases #126

Open
wants to merge 3 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/retry/src/Aeon/Retry/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,7 @@ public function execute(callable $function)
*/
$exceptions = [];

if ($this->retries === 0) {
$lastReturn = $function($this->lastExecution = new Execution(0));

$terminationException = $this->lastExecution->terminationException();

if ($terminationException) {
throw $terminationException;
}

return $lastReturn;
}

for ($retry = 0; $retry < $this->retries; $retry++) {
for ($retry = 0; $retry < ($this->retries + 1); $retry++) {
try {
$lastReturn = $function($this->lastExecution = new Execution($retry, $exceptions));

Expand Down
33 changes: 33 additions & 0 deletions src/retry/tests/Aeon/Retry/Tests/Unit/RetryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,37 @@ public function test_throws_the_last_exception() : void
))->modifyDelay(new ConstantDelay())
->execute($callable);
}

/**
* @dataProvider retryExceptionDataProvider
*/
public function test_throws_the_last_exception_for_given_retries($retries, $expectedException) : void
{
$this->expectExceptionMessage($expectedException);
$queue = [
new \RuntimeException('first'),
new \RuntimeException('second'),
new \RuntimeException('third'),
];

$callable = function () use (&$queue) : void {
throw \array_shift($queue);
};

(new Retry(
new DummyProcess(),
$retries,
TimeUnit::seconds(3)
))->modifyDelay(new ConstantDelay())
->execute($callable);
}

public function retryExceptionDataProvider() : array
{
return [
[0, 'first'],
[1, 'second'],
[2, 'third'],
];
}
}
Loading