Skip to content

Commit

Permalink
Merge pull request #271 from DataDog/anmarchenko/logical_test_session…
Browse files Browse the repository at this point in the history
…_name_for_session_resource

[SDTEST-1375] Use logical test session name as part of test session span's resource instead of test command
  • Loading branch information
anmarchenko authored Dec 19, 2024
2 parents 796ece0 + 7611ec8 commit b8c8238
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def finish
# Return the test session's name which is equal to test command used
# @return [String] the command for this test session.
def name
get_tag(Ext::Test::TAG_COMMAND)
test_visibility.logical_test_session_name || "test_session"
end

# Return the test session's command used to run the tests
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def to_s
def to_integer(value)
value&.to_i
end

def test_visibility
@test_visibility ||= Datadog::CI.send(:test_visibility)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/serializers/test_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def name
end

def resource
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_session.#{@span.get_tag(Ext::Test::TAG_COMMAND)}"
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_session.#{test_visibility.logical_test_session_name}"
end

private
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/test_visibility/serializers/base.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ module Datadog
def to_integer: (String? value) -> Integer?

def content_fields_count: () -> Integer

def test_visibility: () -> Datadog::CI::TestVisibility::Component
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions spec/datadog/ci/test_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Datadog::CI::TestSession do
let(:tracer_span) { Datadog::Tracing::SpanOperation.new("session") }
let(:test_visibility) { spy("test_visibility") }
let(:test_visibility) { spy("test_visibility", logical_test_session_name: "my_test_session") }

before { allow_any_instance_of(described_class).to receive(:test_visibility).and_return(test_visibility) }
subject(:ci_test_session) { described_class.new(tracer_span) }
Expand Down Expand Up @@ -36,11 +36,7 @@
describe "#name" do
subject(:name) { ci_test_session.name }

before do
tracer_span.set_tag(Datadog::CI::Ext::Test::TAG_COMMAND, "test command")
end

it { is_expected.to eq("test command") }
it { is_expected.to eq("my_test_session") }
end

describe "#test_command" do
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/ci/test_visibility/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@

it "returns a new CI test_session span" do
expect(subject).to be_kind_of(Datadog::CI::TestSession)
expect(subject.name).to eq(test_command)
expect(subject.name).to eq(test_visibility.logical_test_session_name)
expect(subject.service).to eq(service)
expect(subject.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
produce_test_session_trace
end

let(:logical_test_session_name) { "logical_test_session_name" }
before do
expect_any_instance_of(Datadog::CI::TestVisibility::Component).to(
receive(:logical_test_session_name).and_return(logical_test_session_name)
)
end

it "serializes test event to messagepack" do
expect_event_header(type: Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION)

Expand All @@ -22,7 +29,7 @@
"name" => "rspec.test_session",
"service" => "rspec-test-suite",
"type" => Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION,
"resource" => "rspec.test_session.#{test_command}"
"resource" => "rspec.test_session.#{logical_test_session_name}"
}
)

Expand Down

0 comments on commit b8c8238

Please sign in to comment.