Class: DistribCore::Leader::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/distrib_core/leader/error_handler.rb

Overview

Default strategy to manage retries of tests.

Direct Known Subclasses

RetryOnDifferentErrorHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception_extractor) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/distrib_core/leader/error_handler.rb', line 8

def initialize(exception_extractor)
  @retryable_exceptions = []
  @retry_attempts = 0
  @retries_per_test = Hash.new(0)

  @fatal_worker_failures = []
  @failed_workers_threshold = 0
  @failed_workers_count = 0

  @exception_extractor = exception_extractor
end

Instance Attribute Details

#failed_workers_countObject

Returns the value of attribute failed_workers_count.



6
7
8
# File 'lib/distrib_core/leader/error_handler.rb', line 6

def failed_workers_count
  @failed_workers_count
end

#failed_workers_thresholdObject

Returns the value of attribute failed_workers_threshold.



5
6
7
# File 'lib/distrib_core/leader/error_handler.rb', line 5

def failed_workers_threshold
  @failed_workers_threshold
end

#fatal_worker_failuresObject

Returns the value of attribute fatal_worker_failures.



5
6
7
# File 'lib/distrib_core/leader/error_handler.rb', line 5

def fatal_worker_failures
  @fatal_worker_failures
end

#retry_attemptsObject

Returns the value of attribute retry_attempts.



5
6
7
# File 'lib/distrib_core/leader/error_handler.rb', line 5

def retry_attempts
  @retry_attempts
end

#retryable_exceptionsObject

Returns the value of attribute retryable_exceptions.



5
6
7
# File 'lib/distrib_core/leader/error_handler.rb', line 5

def retryable_exceptions
  @retryable_exceptions
end

Instance Method Details

#ignore_worker_failure?(exception) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/distrib_core/leader/error_handler.rb', line 46

def ignore_worker_failure?(exception)
  self.failed_workers_count += 1

  return false if missing_exception?(exception) || exceeded_failures_threshold? || fatal_failure?(exception)

  true
end

#retry_test?(test, results, exception) ⇒ Boolean

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


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
# File 'lib/distrib_core/leader/error_handler.rb', line 20

def retry_test?(test, results, exception) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
  return false if retries_per_test[test] >= retry_attempts

  exceptions = exception_extractor.failures_of(results)
  exceptions.push(exception) if exception

  failures_causes = exception_extractor.unpack_causes(exceptions)

  return false if failures_causes.empty?

  if retryable_exceptions.empty?
    retries_per_test[test] += 1
    return true
  end

  retried = failures_causes.all? do |causes|
    causes.any? do |cause|
      retryable_exceptions.include?(cause.original_class)
    end
  end

  retries_per_test[test] += 1 if retried

  retried
end