Class: Datadog::CI::TestRetries::Driver::RetryFailedDynamic

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb

Overview

Dynamic ATR driver: retries failing tests using duration-based retry budgets instead of the flat per-test retry limit. The test is classified once by its initial-attempt duration, and the resulting max-retries count is cached for the lifetime of that test.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#mark_as_retry, #tracks_retry_results?

Constructor Details

#initialize(slow_test_retries, retries_buckets: nil) ⇒ RetryFailedDynamic

Returns a new instance of RetryFailedDynamic.



18
19
20
21
22
23
24
25
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 18

def initialize(slow_test_retries, retries_buckets: nil)
  @slow_test_retries = slow_test_retries
  @retries_buckets = retries_buckets
  @attempts = 0
  @passed_once = false
  @max_attempts = 1
  @duration_recorded = false
end

Instance Attribute Details

#max_attempts ⇒ Object (readonly)

Returns the value of attribute max_attempts.



16
17
18
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 16

def max_attempts
  @max_attempts
end

Instance Method Details

#record_duration(duration) ⇒ Object

Classify the test once based on the initial-attempt duration. Subsequent calls (from retries) are ignored — the first classification sticks.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 42

def record_duration(duration)
  return if @duration_recorded

  retries_buckets = @retries_buckets
  if retries_buckets
    index = @slow_test_retries.retry_bucket_index_for_duration(duration)
    @max_attempts = [1, retries_buckets[index]].max
  else
    @max_attempts = [1, @slow_test_retries.retries_for_duration(duration)].max
  end
  @duration_recorded = true

  Datadog.logger.debug { "Dynamic ATR: duration [#{duration}s], max attempts [#{@max_attempts}]" }
end

#record_retry(test_span) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 31

def record_retry(test_span)
  super

  @attempts += 1
  @passed_once = true if test_span&.passed?

  Datadog.logger.debug { "Dynamic ATR Attempts [#{@attempts} / #{@max_attempts}], Passed: [#{@passed_once}]" }
end

#retry_reason ⇒ Object



57
58
59
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 57

def retry_reason
  Ext::Test::RetryReason::RETRY_FAILED
end

#should_retry? ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/datadog/ci/test_retries/driver/retry_failed_dynamic.rb', line 27

def should_retry?
  @attempts < @max_attempts && !@passed_once
end