Skip to content

Commit fed61a6

Browse files
committed
Fix minitest retry logic for CI.
The previous setup wasn't actually retrying all of the tests I had originally expected, since it was only retrying the `methods_to_retry` tests regardless of error type, but also not retrying any selenium failures in other tests.
1 parent c189eb3 commit fed61a6

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

test/support/retry.rb

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
# While not ideal, retry certain flaky tests in CI.
22
if ENV["CI"] == "true"
33
require "minitest/retry"
4-
Minitest::Retry.use!(
5-
methods_to_retry: [
6-
"Test::AdminUi::Login::TestLocalAndExternalProviders#test_password_fields_only_for_my_account",
7-
"Test::AdminUi::TestApis#test_form",
8-
"Test::Proxy::TestTimeoutsResponse#test_response_closes_when_chunk_delay_exceeds_read_timeout",
9-
],
10-
11-
exceptions_to_retry: [
12-
Selenium::WebDriver::Error::UnknownError,
13-
],
14-
)
4+
5+
module Minitest::Retry
6+
# Instead of relying on minitest-retry's various built-in options (like
7+
# `exceptions_to_retry` and `methods_to_retry`), override it's retry logic
8+
# method completely to allow for more flexibility.
9+
#
10+
# The default options are sort of all-or-nothing (eg, by defining
11+
# `methods_to_retry`, that takes precedence over any other options), to
12+
# this allows for more granular decision making on which errors to retry.
13+
def self.failure_to_retry?(failures = [], klass_method_name, klass)
14+
return false if failures.empty?
15+
16+
errors = failures.map(&:error).map(&:class)
17+
18+
# Retry any Selenium unknown failures anywhere, since these tend to be
19+
# the flakier ones out in CI.
20+
if errors.include?(Selenium::WebDriver::Error::UnknownError)
21+
return true
22+
end
23+
24+
# Retry any failure in some specific tests that might be flaky in CI due
25+
# to specific timing conditions.
26+
case klass_method_name
27+
when "Test::Proxy::TestTimeoutsResponse#test_response_closes_when_chunk_delay_exceeds_read_timeout"
28+
return true
29+
end
30+
31+
false
32+
end
33+
end
34+
35+
Minitest::Retry.use!
1536
end

0 commit comments

Comments
 (0)