Skip to content

Commit

Permalink
first stab on moving the test retries callback to fire after test spa…
Browse files Browse the repository at this point in the history
…n is finished
  • Loading branch information
anmarchenko committed Sep 3, 2024
1 parent e2151ad commit 457b0b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/datadog/ci/test_retries/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def with_retries(&block)
# @type var retry_strategy: Strategy::Base
retry_strategy = nil

test_finished_callback = lambda do |test_span|
test_finished_callback = lambda do |tracer_span|
test_span = Datadog::CI::Test.new(tracer_span)

if retry_strategy.nil?
# we always run test at least once and after first pass create a correct retry strategy
retry_strategy = build_strategy(test_span)
Expand All @@ -81,6 +83,7 @@ def with_retries(&block)
end
end

# TODO: is there a better way to let test_visibility_component know that we are running under retries component?
test_visibility_component.set_test_finished_callback(test_finished_callback)

loop do
Expand Down
17 changes: 14 additions & 3 deletions lib/datadog/ci/test_visibility/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def start_test_suite(test_suite_name, service: nil, tags: {})
def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
if block
@context.trace_test(test_name, test_suite_name, service: service, tags: tags) do |test|
# subscribe on test stop event
if test_finished_callback
events = test.tracer_span.send(:events)
events.after_stop.subscribe do |event|
test_finished_callback&.call(event)
end
end

on_test_started(test)
res = block.call(test)
on_test_finished(test)
Expand Down Expand Up @@ -127,7 +135,12 @@ def deactivate_test_suite(test_suite_name)
@context.deactivate_test_suite(test_suite_name)
end

# sets fiber-local callback to be called when test is finished
# sets fiber-local callback to be called after test is finished

def test_finished_callback
Thread.current[FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY]
end

def set_test_finished_callback(callback)
Thread.current[FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY] = callback
end
Expand Down Expand Up @@ -203,8 +216,6 @@ def on_test_finished(test)
test_optimisation.count_skipped_test(test)

Telemetry.event_finished(test)

Thread.current[FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY]&.call(test)
end

# HELPERS
Expand Down

0 comments on commit 457b0b6

Please sign in to comment.