Skip to content

Commit

Permalink
don't send telemetry event indicating empty coverage for skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 28, 2024
1 parent c7117c1 commit d684100
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/datadog/ci/test_optimisation/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ def stop_coverage(test)
Telemetry.code_coverage_finished(test)

coverage = coverage_collector&.stop

# if test was skipped, we discard coverage data
return if test.skipped?

if coverage.nil? || coverage.empty?
Telemetry.code_coverage_is_empty
return
end

return if test.skipped?

test_source_file = test.source_file

# cucumber's gherkin files are not covered by the code coverage collector
Expand Down
18 changes: 18 additions & 0 deletions spec/datadog/ci/test_optimisation/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@
expect(subject).to be_nil
expect(writer).not_to have_received(:write)
end

it_behaves_like "emits no metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_IS_EMPTY
end

context "when test is skipped and coverage is empty" do
before do
allow_any_instance_of(Datadog::CI::TestOptimisation::Coverage::DDCov).to receive(:stop).and_return(nil)

component.start_coverage(test_span)
test_span.skipped!
end

it "does not write coverage event" do
expect(subject).to be_nil
expect(writer).not_to have_received(:write)
end

it_behaves_like "emits no metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_IS_EMPTY
end

context "when coverage was not collected" do
Expand Down

0 comments on commit d684100

Please sign in to comment.