Skip to content

Commit

Permalink
Retry capybara tests on specific errors, better output
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Aug 24, 2023
1 parent 2f469a9 commit 643bb0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions test/support/retry_on_flaky_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ def self.[](*error_classes, max_tries: 3)
error_classes
end

def capture_exceptions
tries ||= 1
def run_one_method(klass, method_name, reporter)
report_result = nil
max_tries.times do
result = Minitest.run_one_method(klass, method_name)
report_result ||= result
(report_result = result) and break if result.passed?

yield
rescue => err
if (tries +=1) <= max_tries && error_classes.include?(err.class)
puts "Got #{err.message} Error, trying again #{tries}. time"
retry
else
super { raise err }
break unless retryable_failure?(result)
end
reporter.record(report_result)
end

def retryable_failure?(result)
result.failures.map do |failure|
failure.error.to_s
end.any? do |failure_msg|
error_classes.first {|error_class| failure_msg =~ error_class.name }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
class ActiveSupport::TestCase
include CustomAssertions

prepend RetryOnFlakyTests[
extend RetryOnFlakyTests[
# randomly happening on CI
Ferrum::PendingConnectionsError,
# race condition when trying to move mouse to element, can happen e.g. after fade-in/out of modal dialog
Expand Down

0 comments on commit 643bb0a

Please sign in to comment.