Skip to content

Commit

Permalink
add more rspec matchers to span_helpers and greatly simplify tracing …
Browse files Browse the repository at this point in the history
…specs
  • Loading branch information
anmarchenko committed Feb 12, 2024
1 parent b7a4dde commit a18860c
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 457 deletions.
23 changes: 7 additions & 16 deletions spec/datadog/ci/contrib/ci_queue_minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@
expect(test_module_span).not_to be_nil

# test session and module are failed
expect(test_session_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect([test_session_span, test_module_span]).to all have_fail_status

# test suite spans are created for each test as for parallel execution
expect(test_suite_spans).to have(3).items
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) }.sort).to eq(
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS, Datadog::CI::Ext::Test::Status::PASS]
)
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(:status, ["pass", "pass", "fail"])
expect(test_suite_spans).to have_tag_values_no_order(
:suite,
[
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_fail concurrently)",
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_pass concurrently)",
Expand All @@ -63,13 +57,10 @@
# there is test span for every test case
expect(test_spans).to have(3).items
# each test span has its own test suite
expect(test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq).to have(3).items
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 3)

# every test span is connected to test module and test session
test_spans.each do |test_span|
[Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID, Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID].each do |tag|
expect(test_span.get_tag(tag)).not_to be_nil
end
end
expect(test_spans).to all have_test_tag(:test_module_id)
expect(test_spans).to all have_test_tag(:test_session_id)
end
end
22 changes: 8 additions & 14 deletions spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,16 @@ def with_new_rspec_environment
expect(test_module_span).not_to be_nil

# test session and module are failed
expect(test_session_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect([test_session_span, test_module_span]).to all have_fail_status

# test suite spans are created for each test as for parallel execution
expect(test_suite_spans).to have(2).items
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(
:status,
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS]
)
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(
:suite,
[
"SomeTest at ./spec/datadog/ci/contrib/ci_queue_rspec/suite_under_test/some_test_rspec.rb (ci-queue running example [nested fails])",
"SomeTest at ./spec/datadog/ci/contrib/ci_queue_rspec/suite_under_test/some_test_rspec.rb (ci-queue running example [nested foo])"
Expand All @@ -81,13 +78,10 @@ def with_new_rspec_environment
# there is test span for every test case
expect(test_spans).to have(2).items
# each test span has its own test suite
expect(test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq).to have(2).items
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 2)

# every test span is connected to test module and test session
test_spans.each do |test_span|
[Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID, Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID].each do |tag|
expect(test_span.get_tag(tag)).not_to be_nil
end
end
expect(test_spans).to all have_test_tag(:test_module_id)
expect(test_spans).to all have_test_tag(:test_session_id)
end
end
Loading

0 comments on commit a18860c

Please sign in to comment.