Skip to content

Commit

Permalink
add #itr_unskippable! method to a Datadog::CI::Test to mark test_span…
Browse files Browse the repository at this point in the history
… as unskippable by ITR
  • Loading branch information
anmarchenko committed Apr 24, 2024
1 parent f0592d1 commit 67c63db
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/datadog/ci/ext/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Ext
module Test
CONTEXT_ORIGIN = "ciapp-test"

TAG_ARGUMENTS = "test.arguments"
TAG_FRAMEWORK = "test.framework"
TAG_FRAMEWORK_VERSION = "test.framework_version"
TAG_NAME = "test.name"
Expand All @@ -29,6 +28,8 @@ module Test
TAG_ITR_TEST_SKIPPING_COUNT = "test.itr.tests_skipping.count"
TAG_ITR_SKIPPED_BY_ITR = "test.skipped_by_itr"
TAG_ITR_TESTS_SKIPPED = "_dd.ci.itr.tests_skipped"
TAG_ITR_UNSKIPPABLE = "test.itr.unskippable"
TAG_ITR_FORCED_RUN = "test.itr.forced_run"

# Code coverage tags
TAG_CODE_COVERAGE_ENABLED = "test.code_coverage.enabled"
Expand Down
7 changes: 7 additions & 0 deletions lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def set_tag(key, value)
tracer_span.set_tag(key, value)
end

# Removes tag by key.
# @param [String] key the key of the tag.
# @return [void]
def clear_tag(key)
tracer_span.clear_tag(key)
end

# Sets metric value by key.
# @param [String] key the key of the metric.
# @param [Numeric] value the value of the metric.
Expand Down
18 changes: 18 additions & 0 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ def skipped_by_itr?
get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true"
end

# Marks this test as unskippable by the intelligent test runner.
# This must be done before the test execution starts.
#
# Examples of tests that should be unskippable:
# - tests that read files from disk
# - tests that make network requests
# - tests that call external processes
# - tests that use forking or threading
#
# @return [void]
def itr_unskippable!
set_tag(Ext::Test::TAG_ITR_UNSKIPPABLE, "true")
if skipped_by_itr?
clear_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR)
set_tag(Ext::Test::TAG_ITR_FORCED_RUN, "true")
end
end

# Sets the status of the span to "pass".
# @return [void]
def passed!
Expand Down
6 changes: 4 additions & 2 deletions sig/datadog/ci/ext/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Datadog
module Test
CONTEXT_ORIGIN: "ciapp-test"

TAG_ARGUMENTS: "test.arguments"

TAG_FRAMEWORK: "test.framework"

TAG_FRAMEWORK_VERSION: "test.framework_version"
Expand Down Expand Up @@ -42,6 +40,10 @@ module Datadog

TAG_ITR_TESTS_SKIPPED: "_dd.ci.itr.tests_skipped"

TAG_ITR_UNSKIPPABLE: "test.itr.unskippable"

TAG_ITR_FORCED_RUN: "test.itr.forced_run"

TAG_CODE_COVERAGE_ENABLED: "test.code_coverage.enabled"

TAG_TEST_SESSION_ID: "_test.session_id"
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/span.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module Datadog

def set_tag: (String key, untyped? value) -> void

def clear_tag: (String key) -> void

def set_metric: (String key, untyped value) -> void

def set_tags: (Hash[untyped, untyped] tags) -> void
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 @@ -8,6 +8,7 @@ module Datadog
def test_module_id: () -> String?
def test_session_id: () -> String?
def skipped_by_itr?: () -> bool
def itr_unskippable!: () -> void
def source_file: () -> String?
def parameters: () -> String?

Expand Down
8 changes: 8 additions & 0 deletions spec/datadog/ci/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@
end
end

describe "#clear_tag" do
it "clears the tag" do
expect(tracer_span).to receive(:clear_tag).with("foo")

span.clear_tag("foo")
end
end

describe "#set_tags" do
it "sets the tags" do
expect(tracer_span).to receive(:set_tags).with({"foo" => "bar", "baz" => "qux"})
Expand Down
28 changes: 28 additions & 0 deletions spec/datadog/ci/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@
end
end

describe "#itr_unskippable!" do
context "when test is not skipped by ITR" do
before do
allow(ci_test).to receive(:skipped_by_itr?).and_return(false)
end

it "sets unskippable tag" do
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_UNSKIPPABLE, "true")

ci_test.itr_unskippable!
end
end

context "when test is skipped by ITR" do
before do
allow(ci_test).to receive(:skipped_by_itr?).and_return(true)
end

it "sets unskippable tag, removes skipped by ITR tag, and sets forced run tag" do
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_UNSKIPPABLE, "true")
expect(tracer_span).to receive(:clear_tag).with(Datadog::CI::Ext::Test::TAG_ITR_SKIPPED_BY_ITR)
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_FORCED_RUN, "true")

ci_test.itr_unskippable!
end
end
end

describe "#set_parameters" do
let(:parameters) { {"foo" => "bar", "baz" => "qux"} }

Expand Down

0 comments on commit 67c63db

Please sign in to comment.