|
1 | 1 | # While not ideal, retry certain flaky tests in CI. |
2 | 2 | if ENV["CI"] == "true" |
3 | 3 | 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! |
15 | 36 | end |
0 commit comments