Skip to content

Commit

Permalink
additional debug logging to investigate issues with test suite level …
Browse files Browse the repository at this point in the history
…visibility
  • Loading branch information
anmarchenko committed Dec 12, 2023
1 parent 385117e commit b77fe2c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ def finish

CI.deactivate_test(self)
end

# Span id of the running test suite this test belongs to.
# @return [String] the span id of the test suite.
def test_suite_id
get_tag(Ext::Test::TAG_TEST_SUITE_ID)
end

def test_suite_name
get_tag(Ext::Test::TAG_SUITE)
end

# Span id of the running test module this test belongs to.
# @return [String] the span id of the test module.
def test_module_id
get_tag(Ext::Test::TAG_TEST_MODULE_ID)
end

# Span id of the running test module this test belongs to.
# @return [String] the span id of the test session.
def test_session_id
get_tag(Ext::Test::TAG_TEST_SESSION_ID)
end
end
end
end
26 changes: 26 additions & 0 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def build_test_suite(tracer_span, tags)
def build_test(tracer_span, tags)
test = Test.new(tracer_span)
set_initial_tags(test, tags)
validate_test_suite_level_visibility_correctness(test)
test
end

Expand Down Expand Up @@ -287,6 +288,31 @@ def start_datadog_tracer_span(span_name, span_options, &block)
def null_span
@null_span ||= NullSpan.new
end

def validate_test_suite_level_visibility_correctness(test)
return unless test_suite_level_visibility_enabled

if test.test_suite_id.nil?
Datadog.logger.debug do
"Test [#{test.name}] does not have a test suite associated with it. " \
"Expected test suite [#{test.test_suite_name}] to be running."
end
end

if test.test_module_id.nil?
Datadog.logger.debug do
"Test [#{test.name}] does not have a test module associated with it. " \
"Make sure that there is a test module running within a session."
end
end

if test.test_session_id.nil?
Datadog.logger.debug do
"Test [#{test.name}] does not have a test session associated with it. " \
"Make sure that there is a test session running."
end
end
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions sig/datadog/ci/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module Datadog
module CI
class Test < Span
def finish: () -> void
def test_suite_id: () -> String?
def test_suite_name: () -> String?
def test_module_id: () -> String?
def test_session_id: () -> String?
end
end
end
2 changes: 2 additions & 0 deletions sig/datadog/ci/test_visibility/recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ module Datadog
def start_datadog_tracer_span: (String span_name, Hash[untyped, untyped] span_options) ?{ (untyped) -> untyped } -> untyped

def set_inherited_globals: (Hash[untyped, untyped] tags) -> void

def validate_test_suite_level_visibility_correctness: (Datadog::CI::Test test) -> void
end
end
end
Expand Down
50 changes: 50 additions & 0 deletions spec/datadog/ci/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,54 @@
expect(Datadog::CI).to have_received(:deactivate_test).with(ci_test)
end
end

describe "#test_suite_id" do
subject(:test_suite_id) { ci_test.test_suite_id }
let(:ci_test) { described_class.new(tracer_span) }

before do
allow(tracer_span).to receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID).and_return("test suite id")
end

it { is_expected.to eq("test suite id") }
end

describe "#test_suite_name" do
subject(:test_suite_name) { ci_test.test_suite_name }
let(:ci_test) { described_class.new(tracer_span) }

before do
allow(tracer_span).to(
receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_SUITE).and_return("test suite name")
)
end

it { is_expected.to eq("test suite name") }
end

describe "#test_module_id" do
subject(:test_module_id) { ci_test.test_module_id }
let(:ci_test) { described_class.new(tracer_span) }

before do
allow(tracer_span).to(
receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID).and_return("test module id")
)
end

it { is_expected.to eq("test module id") }
end

describe "#test_session_id" do
subject(:test_session_id) { ci_test.test_session_id }
let(:ci_test) { described_class.new(tracer_span) }

before do
allow(tracer_span).to(
receive(:get_tag).with(Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID).and_return("test session id")
)
end

it { is_expected.to eq("test session id") }
end
end

0 comments on commit b77fe2c

Please sign in to comment.