Class: Datadog::CI::TestRetries::Strategy::RetryNew

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

Constant Summary collapse

DEFAULT_TOTAL_TESTS_COUNT =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled:) ⇒ RetryNew

Returns a new instance of RetryNew.



16
17
18
19
20
21
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 16

def initialize(enabled:)
  @enabled = enabled
  # total maximum number of new tests to retry (will be set based on the total number of tests in the session)
  @total_limit = 0
  @retried_count = 0
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



14
15
16
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 14

def enabled
  @enabled
end

#max_attempts_thresholdsObject (readonly)

Returns the value of attribute max_attempts_thresholds.



14
15
16
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 14

def max_attempts_thresholds
  @max_attempts_thresholds
end

#retried_countObject (readonly)

Returns the value of attribute retried_count.



14
15
16
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 14

def retried_count
  @retried_count
end

#total_limitObject (readonly)

Returns the value of attribute total_limit.



14
15
16
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 14

def total_limit
  @total_limit
end

Instance Method Details

#build_driver(test_span) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 49

def build_driver(test_span)
  Datadog.logger.debug do
    "#{test_span.name} is new, will be retried"
  end
  @retried_count += 1

  Driver::RetryNew.new(test_span, max_attempts_thresholds: @max_attempts_thresholds)
end

#configure(library_settings, test_session) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 37

def configure(library_settings, test_session)
  @enabled &&= library_settings.early_flake_detection_enabled? && library_settings.known_tests_enabled?

  return unless @enabled

  # mark early flake detection enabled for test session
  test_session.set_tag(Ext::Test::TAG_EARLY_FLAKE_ENABLED, "true")

  set_max_attempts_thresholds(library_settings)
  calculate_total_retries_limit(library_settings, test_session)
end

#covers?(test_span) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/ci/test_retries/strategy/retry_new.rb', line 23

def covers?(test_span)
  return false unless @enabled

  if @retried_count >= @total_limit
    Datadog.logger.debug do
      "Retry new tests limit reached: [#{@retried_count}] out of [#{@total_limit}]"
    end
    @enabled = false
    mark_test_session_faulty(Datadog::CI.active_test_session)
  end

  @enabled && !test_span.skipped? && test_span.is_new?
end