Skip to content

Commit

Permalink
don't collect code coverage for retried tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 28, 2024
1 parent d684100 commit a503ec2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/ci/test_optimisation/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions sig/datadog/ci/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Datadog
def itr_unskippable!: () -> void
def source_file: () -> String?
def parameters: () -> String?
def is_retry?: () -> bool

private

Expand Down
13 changes: 13 additions & 0 deletions spec/datadog/ci/test_optimisation/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/datadog/ci/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a503ec2

Please sign in to comment.