Skip to content

Commit

Permalink
retry fragile tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Aug 3, 2017
1 parent 6b28e61 commit 06fdfbc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions RetryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Enqueue\Test;

trait RetryTrait
{
public function runBare()
{
$e = null;

$numberOfRetires = $this->getNumberOfRetries();
for ($i = 0; $i < $numberOfRetires; ++$i) {
try {
parent::runBare();

return;
} catch (\Exception $e) {
// last one thrown below
}
}

if ($e) {
throw $e;
}
}

/**
* @return int
*/
private function getNumberOfRetries()
{
$annotations = $this->getAnnotations();

if (isset($annotations['method']['retry'])) {
return $annotations['method']['retry'];
}

if (isset($annotations['class']['retry'][0])) {
return $annotations['class']['retry'][0];
}

return 1;
}
}

0 comments on commit 06fdfbc

Please sign in to comment.