summaryrefslogtreecommitdiff
path: root/qa/qa/support/retrier.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/support/retrier.rb')
-rw-r--r--qa/qa/support/retrier.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/qa/qa/support/retrier.rb b/qa/qa/support/retrier.rb
new file mode 100644
index 00000000000..8be4e9f5365
--- /dev/null
+++ b/qa/qa/support/retrier.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module QA
+ module Support
+ module Retrier
+ module_function
+
+ def retry_on_exception(max_attempts: 3, reload_page: nil, sleep_interval: 0.5)
+ QA::Runtime::Logger.debug("with retry_on_exception: max_attempts #{max_attempts}; sleep_interval #{sleep_interval}")
+
+ attempts = 0
+
+ begin
+ QA::Runtime::Logger.debug("Attempt number #{attempts + 1}")
+ yield
+ rescue StandardError, RSpec::Expectations::ExpectationNotMetError
+ sleep sleep_interval
+ reload_page.refresh if reload_page
+ attempts += 1
+
+ retry if attempts < max_attempts
+ QA::Runtime::Logger.debug("Raising exception after #{max_attempts} attempts")
+ raise
+ end
+ end
+ end
+ end
+end