Skip to content

Commit

Permalink
rename strategies to drivers in test retries component
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 16, 2024
1 parent 532a1a9 commit b2d133c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 deletions lib/datadog/ci/test_retries/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module TestRetries
# - retrying failed tests - improve success rate of CI pipelines
# - retrying new tests - detect flaky tests as early as possible to prevent them from being merged
class Component
FIBER_LOCAL_CURRENT_RETRY_STRATEGY_KEY = :__dd_current_retry_strategy
FIBER_LOCAL_CURRENT_RETRY_DRIVER_KEY = :__dd_current_retry_driver

DEFAULT_TOTAL_TESTS_COUNT = 100

Expand Down Expand Up @@ -120,18 +120,18 @@ def configure(library_settings, test_session)
end

def with_retries(&block)
self.current_retry_strategy = nil
self.current_retry_driver = nil

loop do
yield

break unless current_retry_strategy&.should_retry?
break unless current_retry_driver&.should_retry?
end
ensure
self.current_retry_strategy = nil
self.current_retry_driver = nil
end

def build_strategy(test_span)
def build_driver(test_span)
@mutex.synchronize do
if should_retry_new_test?(test_span)
Datadog.logger.debug do
Expand All @@ -154,27 +154,27 @@ def build_strategy(test_span)
end

def record_test_finished(test_span)
if current_retry_strategy.nil?
# we always run test at least once and after the first pass create a correct retry strategy
self.current_retry_strategy = build_strategy(test_span)
if current_retry_driver.nil?
# we always run test at least once and after the first pass create a correct retry driver
self.current_retry_driver = build_driver(test_span)
else
# after each retry we record the result, strategy will decide if we should retry again
current_retry_strategy&.record_retry(test_span)
# after each retry we record the result, the driver will decide if we should retry again
current_retry_driver&.record_retry(test_span)
end
end

def record_test_span_duration(tracer_span)
current_retry_strategy&.record_duration(tracer_span.duration)
current_retry_driver&.record_duration(tracer_span.duration)
end

private

def current_retry_strategy
Thread.current[FIBER_LOCAL_CURRENT_RETRY_STRATEGY_KEY]
def current_retry_driver
Thread.current[FIBER_LOCAL_CURRENT_RETRY_DRIVER_KEY]
end

def current_retry_strategy=(strategy)
Thread.current[FIBER_LOCAL_CURRENT_RETRY_STRATEGY_KEY] = strategy
def current_retry_driver=(driver)
Thread.current[FIBER_LOCAL_CURRENT_RETRY_DRIVER_KEY] = driver
end

def should_retry_failed_test?(test_span)
Expand Down
8 changes: 4 additions & 4 deletions sig/datadog/ci/test_retries/component.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Datadog
module CI
module TestRetries
class Component
FIBER_LOCAL_CURRENT_RETRY_STRATEGY_KEY: Symbol
FIBER_LOCAL_CURRENT_RETRY_DRIVER_KEY: Symbol

DEFAULT_TOTAL_TESTS_COUNT: 100

Expand Down Expand Up @@ -36,17 +36,17 @@ module Datadog

def with_retries: () { () -> void } -> void

def build_strategy: (Datadog::CI::Test test) -> Datadog::CI::TestRetries::Driver::Base
def build_driver: (Datadog::CI::Test test) -> Datadog::CI::TestRetries::Driver::Base

def record_test_finished: (Datadog::CI::Test test) -> void

def record_test_span_duration: (Datadog::Tracing::SpanOperation span) -> void

private

def current_retry_strategy: () -> Datadog::CI::TestRetries::Driver::Base?
def current_retry_driver: () -> Datadog::CI::TestRetries::Driver::Base?

def current_retry_strategy=: (Datadog::CI::TestRetries::Driver::Base? strategy) -> void
def current_retry_driver=: (Datadog::CI::TestRetries::Driver::Base? driver) -> void

def should_retry_failed_test?: (Datadog::CI::Test test) -> bool

Expand Down

0 comments on commit b2d133c

Please sign in to comment.