Skip to content

Commit

Permalink
Retry capybara tests on specific errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Aug 24, 2023
1 parent 8a7e69b commit 823714d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/support/retry_on_flaky_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Include in `test_helper.rb` like this:
#
# class ActiveSupport::TestCase
# prepend RetryOnFlakyTests[FlakyError, AnotherFlakyError, max_tries: 3]
# end

module RetryOnFlakyTests
def self.[](*error_classes, max_tries: 3)
Module.new do
define_method :max_tries do
max_tries
end

define_method :error_classes do
error_classes
end

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?

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
end
end
10 changes: 10 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
class ActiveSupport::TestCase
include CustomAssertions

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
Ferrum::CoordinatesNotFoundError,
# race condition when trying to click element, can happen e.g. after fade-in/out of modal dialog
Capybara::Cuprite::MouseEventFailed,
max_tries: 3
]

# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
Expand Down

0 comments on commit 823714d

Please sign in to comment.