Skip to content

Commit

Permalink
add tag test.is_new
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 6, 2024
1 parent bf646b6 commit 209d62b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/datadog/ci/ext/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module Test

# Tags for test retries
TAG_IS_RETRY = "test.is_retry" # true if test was retried by datadog-ci library
TAG_IS_NEW = "test.is_new" # true if test was marked as new by new test retries (early flake detection)

# internal APM tag to mark a span as a test span
TAG_SPAN_KIND = "span.kind"
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_retries/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_strategy(test_span)
if should_retry_new_test?(test_span)
Datadog.logger.debug("New test retry starts")

Strategy::RetryNew.new(duration_thresholds: @retry_new_tests_duration_thresholds)
Strategy::RetryNew.new(test_span, duration_thresholds: @retry_new_tests_duration_thresholds)
elsif should_retry_failed_test?(test_span)
Datadog.logger.debug("Failed test retry starts")
@retry_failed_tests_count += 1
Expand Down
11 changes: 10 additions & 1 deletion lib/datadog/ci/test_retries/strategy/retry_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ module TestRetries
module Strategy
# retry every new test up to 10 times (early flake detection)
class RetryNew < Base
def initialize(duration_thresholds:)
def initialize(test_span, duration_thresholds:)
@duration_thresholds = duration_thresholds
@attempts = 0
# will be changed based on test span duration
@max_attempts = 10

mark_new_test(test_span)
end

def should_retry?
Expand All @@ -25,6 +27,7 @@ def record_retry(test_span)
super

@attempts += 1
mark_new_test(test_span)

Datadog.logger.debug { "Retry Attempts [#{@attempts} / #{@max_attempts}]" }
end
Expand All @@ -34,6 +37,12 @@ def record_duration(duration)

Datadog.logger.debug { "Recorded test duration of [#{duration}], new Max Attempts value is [#{@max_attempts}]" }
end

private

def mark_new_test(test_span)
test_span.set_tag(Ext::Test::TAG_IS_NEW, "true")
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/ext/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ module Datadog

TAG_IS_RETRY: "test.is_retry"

TAG_IS_NEW: "test.is_new"

module Status
PASS: "pass"

Expand Down
6 changes: 5 additions & 1 deletion sig/datadog/ci/test_retries/strategy/retry_new.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module Datadog
@attempts: Integer
@max_attempts: Integer

def initialize: (duration_thresholds: Datadog::CI::Remote::SlowTestRetries) -> void
def initialize: (Datadog::CI::Test test_span, duration_thresholds: Datadog::CI::Remote::SlowTestRetries) -> void

private

def mark_new_test: (Datadog::CI::Test test_span) -> void
end
end
end
Expand Down
18 changes: 17 additions & 1 deletion spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -982,10 +982,14 @@ def rspec_skipped_session_run
# it retried the new test 10 times
expect(test_spans_by_test_name["nested foo"]).to have(11).item

# count how many spans were marked as retries
# count how many tests were marked as retries
retries_count = test_spans.count { |span| span.get_tag("test.is_retry") == "true" }
expect(retries_count).to eq(10)

# count how many tests were marked as new
new_tests_count = test_spans.count { |span| span.get_tag("test.is_new") == "true" }
expect(new_tests_count).to eq(11)

expect(test_suite_spans).to have(1).item
expect(test_suite_spans.first).to have_fail_status

Expand All @@ -1011,6 +1015,10 @@ def rspec_skipped_session_run
retries_count = test_spans.count { |span| span.get_tag("test.is_retry") == "true" }
expect(retries_count).to eq(5)

# count how many tests were marked as new
new_tests_count = test_spans.count { |span| span.get_tag("test.is_new") == "true" }
expect(new_tests_count).to eq(6)

expect(test_suite_spans).to have(1).item
expect(test_session_span).to have_fail_status
end
Expand Down Expand Up @@ -1045,6 +1053,10 @@ def rspec_skipped_session_run
retries_count = test_spans.count { |span| span.get_tag("test.is_retry") == "true" }
expect(retries_count).to eq(14)

# count how many tests were marked as new
new_tests_count = test_spans.count { |span| span.get_tag("test.is_new") == "true" }
expect(new_tests_count).to eq(11)

expect(test_suite_spans).to have(1).item
expect(test_suite_spans.first).to have_pass_status

Expand Down Expand Up @@ -1087,6 +1099,10 @@ def rspec_skipped_session_run
retries_count = test_spans.count { |span| span.get_tag("test.is_retry") == "true" }
expect(retries_count).to eq(20)

# count how many tests were marked as new
new_tests_count = test_spans.count { |span| span.get_tag("test.is_new") == "true" }
expect(new_tests_count).to eq(22)

expect(test_suite_spans).to have(1).item
expect(test_suite_spans.first).to have_pass_status

Expand Down

0 comments on commit 209d62b

Please sign in to comment.