Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Make number of tries in `retry_block` configurable

Christophe Bliard4add7cc86a98
diff --git a/spec/support/edit_fields/edit_field.rb b/spec/support/edit_fields/edit_field.rb
index 703d4903d94..e159972abac 100644
--- a/spec/support/edit_fields/edit_field.rb
+++ b/spec/support/edit_fields/edit_field.rb
@@ -89,7 +89,7 @@ class EditField
##
# Activate the field and check it opened correctly
def activate!(expect_open: true)
- retry_block do
+ retry_block(args: { tries: 2 }) do
unless active?
SeleniumHubWaiter.wait unless using_cuprite?
scroll_to_and_click(display_element)
diff --git a/spec/support/rspec_retry.rb b/spec/support/rspec_retry.rb
index bca85359e63..3542241c2d0 100644
--- a/spec/support/rspec_retry.rb
+++ b/spec/support/rspec_retry.rb
@@ -29,7 +29,17 @@ end
##
# Allow specific code blocks to retry on specific errors
Retriable.configure do |c|
- c.intervals = [1, 1, 2]
+ # Setting intervals overrides `tries`, `base_interval`, `max_interval`,
+ # `rand_factor`, and `multiplier` parameters and thus ruins the benefit of
+ # calling `retry_block` with `args: { tries: _ }` argument.
+ #
+ # Prefer setting `base_interval`, `max_interval`, `rand_factor`, and
+ # `multiplier` instead to keep the benefit of `args: { tries: _ }` argument.
+ #
+ # This will generate the following intervals: [0.5, 0.75, 1.125, ~1.7, ~2.5, ~3.8, ...]
+ c.base_interval = 0.5
+ c.multiplier = 1.5
+ c.rand_factor = 0.0
end
##
@@ -42,18 +52,18 @@ def retry_block(args: {}, screenshot: false, &block)
end
log_errors = Proc.new do |exception, try, elapsed_time, next_interval|
- max_tries = args[:tries] || (RSpec.current_example.metadata[:retry].to_i + 1)
+ max_tries = args[:tries] || Retriable.config.tries
exception_source_lines = backtrace_up_to_spec_file(exception)
- next_try_message = next_interval ? "#{next_interval} seconds until the next try" : "last try"
+ next_try_message = next_interval ? "waiting #{next_interval} seconds until the next try" : "it was the last try"
# use stderr directly to prevent having StructuredWarnings::StandardWarning
# messy and useless output
$stderr.puts <<~MSG # rubocop:disable Style/StderrPuts
- -- rspec-retry #{try}/#{max_tries}--
+ -- rspec-retry: failed try #{try} of #{max_tries} max --
#{exception.class}: '#{exception.message}'
occurred on #{exception_source_lines.first}
backtrace:
#{exception_source_lines.map { " #{_1}" }.join("\n")}
- #{try} tries in #{elapsed_time} seconds, #{next_try_message}.
+ ran #{try} #{'try'.pluralize(try)} in #{elapsed_time} seconds, #{next_try_message}.
--
MSG