Skip to content

Commit

Permalink
Retry capybara tests on specific errors, fix error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Aug 24, 2023
1 parent 6135ef5 commit 2f469a9
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions test/support/retry_on_flaky_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
# prepend RetryOnFlakyTests[FlakyError, AnotherFlakyError, max_tries: 3]
# end

class RetryOnFlakyTests < Module
module RetryOnFlakyTests
def self.[](*error_classes, max_tries: 3)
Module.new do
define_method :run do
tries ||= 1
super()
rescue *error_classes => err
raise unless (tries +=1) <= max_tries
define_method :max_tries do
max_tries
end

puts "Got #{err.class.name} Error, trying again #{tries}. time"
retry
define_method :error_classes do
error_classes
end

define_method :capture_exceptions do |&block|
block.call
def capture_exceptions
tries ||= 1

yield
rescue => err
if error_classes.include?(err.class)
raise
if (tries +=1) <= max_tries && error_classes.include?(err.class)
puts "Got #{err.message} Error, trying again #{tries}. time"
retry
else
super(&->{ raise err })
super { raise err }
end
end
end
Expand Down

0 comments on commit 2f469a9

Please sign in to comment.