Skip to content

Commit 06fdfbc

Browse files
committed
retry fragile tests.
1 parent 6b28e61 commit 06fdfbc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

RetryTrait.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Enqueue\Test;
4+
5+
trait RetryTrait
6+
{
7+
public function runBare()
8+
{
9+
$e = null;
10+
11+
$numberOfRetires = $this->getNumberOfRetries();
12+
for ($i = 0; $i < $numberOfRetires; ++$i) {
13+
try {
14+
parent::runBare();
15+
16+
return;
17+
} catch (\Exception $e) {
18+
// last one thrown below
19+
}
20+
}
21+
22+
if ($e) {
23+
throw $e;
24+
}
25+
}
26+
27+
/**
28+
* @return int
29+
*/
30+
private function getNumberOfRetries()
31+
{
32+
$annotations = $this->getAnnotations();
33+
34+
if (isset($annotations['method']['retry'])) {
35+
return $annotations['method']['retry'];
36+
}
37+
38+
if (isset($annotations['class']['retry'][0])) {
39+
return $annotations['class']['retry'][0];
40+
}
41+
42+
return 1;
43+
}
44+
}

0 commit comments

Comments
 (0)