From 06fdfbcc0cef03c4b0dc77db9a525572b1585255 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 3 Aug 2017 14:03:22 +0300 Subject: [PATCH] retry fragile tests. --- RetryTrait.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 RetryTrait.php diff --git a/RetryTrait.php b/RetryTrait.php new file mode 100644 index 0000000..27ef3f5 --- /dev/null +++ b/RetryTrait.php @@ -0,0 +1,44 @@ +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; + } +}