Skip to content

Commit

Permalink
connect test to the currently active test module
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 30, 2023
1 parent 7a6af86 commit 275c553
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
13 changes: 10 additions & 3 deletions lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,18 @@ def trace_test(test_name, service_name: nil, operation_name: "test", tags: {}, &
service_name ||= test_session.service

tags = test_session.inheritable_tags.merge(tags)

tags[Ext::Test::TAG_TEST_SESSION_ID] = test_session.id
end

test_module = active_test_module
if test_module
tags[Ext::Test::TAG_TEST_MODULE_ID] = test_module.id
tags[Ext::Test::TAG_MODULE] = test_module.name
end

tags[Ext::Test::TAG_NAME] = test_name

span_options = {
resource: test_name,
service: service_name,
Expand All @@ -103,9 +113,6 @@ def trace_test(test_name, service_name: nil, operation_name: "test", tags: {}, &
continue_from: Datadog::Tracing::TraceDigest.new
}

tags[Ext::Test::TAG_NAME] = test_name
tags[Ext::Test::TAG_TEST_SESSION_ID] = test_session.id if test_session

if block
Datadog::Tracing.trace(operation_name, **span_options) do |tracer_span, trace|
set_trace_origin(trace)
Expand Down
76 changes: 53 additions & 23 deletions spec/datadog/ci/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,36 +250,66 @@
test_session
end

it "returns a new CI test span using service from the test session" do
expect(subject).to be_kind_of(Datadog::CI::Test)
expect(subject.name).to eq(test_name)
expect(subject.service).to eq(session_service_name)
end
context "when there is no active test module" do
it "returns a new CI test span using service from the test session" do
expect(subject).to be_kind_of(Datadog::CI::Test)
expect(subject.name).to eq(test_name)
expect(subject.service).to eq(session_service_name)
end

it "sets the provided tags correctly while inheriting some tags from the session" do
expect(subject.get_tag("test.framework")).to eq("my-framework")
expect(subject.get_tag("test.framework_version")).to eq("1.0")
expect(subject.get_tag("my.tag")).to eq("my_value")
expect(subject.get_tag("my.session.tag")).to be_nil
end
it "sets the provided tags correctly while inheriting some tags from the session" do
expect(subject.get_tag("test.framework")).to eq("my-framework")
expect(subject.get_tag("test.framework_version")).to eq("1.0")
expect(subject.get_tag("my.tag")).to eq("my_value")
expect(subject.get_tag("my.session.tag")).to be_nil
end

it "connects the test span to the test session" do
expect(subject.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID)).to eq(test_session.id.to_s)
end
it "connects the test span to the test session" do
expect(subject.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID)).to eq(test_session.id.to_s)
end

it "starts a new trace" do
expect(subject.tracer_span.trace_id).not_to eq(test_session.tracer_span.trace_id)
end

it "starts a new trace" do
expect(subject.tracer_span.trace_id).not_to eq(test_session.tracer_span.trace_id)
it_behaves_like "span with environment tags"
it_behaves_like "span with default tags"
it_behaves_like "span with runtime tags"

it_behaves_like "trace with ciapp-test origin" do
let(:trace_under_test) do
subject.finish

trace
end
end
end

it_behaves_like "span with environment tags"
it_behaves_like "span with default tags"
it_behaves_like "span with runtime tags"
context "when there is an active test module" do
let(:module_name) { "my-module" }

it_behaves_like "trace with ciapp-test origin" do
let(:trace_under_test) do
subject.finish
let(:test_module) do
recorder.start_test_module(module_name)
end

trace
before do
test_module
end

it "returns a new CI test span" do
expect(subject).to be_kind_of(Datadog::CI::Test)
expect(subject.name).to eq(test_name)
end

it "sets the provided tags correctly while inheriting some tags from the session" do
expect(subject.get_tag("test.framework")).to eq("my-framework")
expect(subject.get_tag("test.framework_version")).to eq("1.0")
expect(subject.get_tag("my.tag")).to eq("my_value")
end

it "connects the test span to the test module" do
expect(subject.get_tag(Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID)).to eq(test_module.id.to_s)
expect(subject.get_tag(Datadog::CI::Ext::Test::TAG_MODULE)).to eq(module_name)
end
end
end
Expand Down

0 comments on commit 275c553

Please sign in to comment.