Module: Minitest::OptionalRetry

Included in:
IntransientCapybaraTest
Defined in:
lib/intransient_capybara/minitest_retry.rb

Constant Summary collapse

GLOBAL_RETRY_LIMIT =
25
@@global_retry_count =
Atomic.new(0)

Instance Method Summary collapse

Instance Method Details

#run_one_method(klass, method_name, reporter) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/intransient_capybara/minitest_retry.rb', line 11

def run_one_method(klass, method_name, reporter)
  first_result = nil
  report_result = nil

  retries = [ENV.fetch('MINITEST_RETRY_COUNT', 3).to_i, 1].max

  test_executions = 0
  while test_executions < retries do
    test_executions += 1

    result = Minitest.run_one_method(klass, method_name)

    first_result ||= result

    if result.passed? || result.skipped?
      unless ENV.fetch('TRANSIENT_TESTS_REPORT_FAILURE', false) == 'true'
        report_result = result
      end
      break
    else
      if @@global_retry_count.value >= GLOBAL_RETRY_LIMIT
        puts 'We hit the global retry limit, you probably have a more global issue going on.  We will not try to rerun transients anymore.'
        break
      end

      if result.failure.exception.present? && result.failure.exception.class.to_s == 'Capybara::Poltergeist::DeadClient'
        puts "PhantomJS died!!!! - #{klass.to_s}##{method_name}"
        test_executions -= 1
        first_result = nil
        next
      end

      puts "Test failed!!!! - #{klass.to_s}##{method_name}"

      @@global_retry_count.update { |v| v + 1 }
    end

  end

  report_result ||= first_result

  if !first_result.passed? && report_result.passed?
    puts "#{klass.to_s}##{method_name} IS TRANSIENT!!!!! IT FAILED THE FIRST TRY THEN PASSED IN RETRIES"
  end

  reporter.record(report_result)
end