diff --git a/lib/datadog/ci/test.rb b/lib/datadog/ci/test.rb index 513a228d..97744c59 100644 --- a/lib/datadog/ci/test.rb +++ b/lib/datadog/ci/test.rb @@ -70,6 +70,12 @@ def skipped_by_itr? get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true" end + # Returns "true" if test span represents a retry. + # @return [Boolean] true if this test is a retry, false otherwise. + def is_retry? + get_tag(Ext::Test::TAG_IS_RETRY) == "true" + end + # Marks this test as unskippable by the intelligent test runner. # This must be done before the test execution starts. # diff --git a/lib/datadog/ci/test_optimisation/component.rb b/lib/datadog/ci/test_optimisation/component.rb index 465fe5c1..1920b3e7 100644 --- a/lib/datadog/ci/test_optimisation/component.rb +++ b/lib/datadog/ci/test_optimisation/component.rb @@ -99,12 +99,15 @@ def code_coverage? def start_coverage(test) return if !enabled? || !code_coverage? + return if test.is_retry? + Telemetry.code_coverage_started(test) coverage_collector&.start end def stop_coverage(test) return if !enabled? || !code_coverage? + return if test.is_retry? Telemetry.code_coverage_finished(test) diff --git a/sig/datadog/ci/test.rbs b/sig/datadog/ci/test.rbs index 62f7b534..d264178c 100644 --- a/sig/datadog/ci/test.rbs +++ b/sig/datadog/ci/test.rbs @@ -11,6 +11,7 @@ module Datadog def itr_unskippable!: () -> void def source_file: () -> String? def parameters: () -> String? + def is_retry?: () -> bool private diff --git a/spec/datadog/ci/test_optimisation/component_spec.rb b/spec/datadog/ci/test_optimisation/component_spec.rb index 1b946405..c7d462fe 100644 --- a/spec/datadog/ci/test_optimisation/component_spec.rb +++ b/spec/datadog/ci/test_optimisation/component_spec.rb @@ -166,6 +166,19 @@ end it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_STARTED, 1 + + context "when test is a retry" do + before do + test_span.set_tag(Datadog::CI::Ext::Test::TAG_IS_RETRY, "true") + end + + it "does not start coverage" do + expect(component).not_to receive(:coverage_collector) + + subject + expect(component.stop_coverage(test_span)).to be_nil + end + end end context "when JRuby and code coverage is enabled" do diff --git a/spec/datadog/ci/test_spec.rb b/spec/datadog/ci/test_spec.rb index 0b5924ee..98c16a70 100644 --- a/spec/datadog/ci/test_spec.rb +++ b/spec/datadog/ci/test_spec.rb @@ -322,4 +322,24 @@ expect(ci_test.parameters).to eq(parameters) end end + + describe "#is_retry?" do + subject(:is_retry) { ci_test.is_retry? } + + context "when tag is set" do + before do + allow(tracer_span).to( + receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_IS_RETRY).and_return("true") + ) + end + + it { is_expected.to be true } + end + + context "when tag is not set" do + before { allow(tracer_span).to receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_IS_RETRY).and_return(nil) } + + it { is_expected.to be false } + end + end end