From 055cac545676a39a9ec2975a0a011a2b260692d1 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 16 Jan 2024 16:39:15 +0100 Subject: [PATCH] [minitest] remove test suite prefix from the test name --- lib/datadog/ci/contrib/minitest/hooks.rb | 4 +-- .../contrib/minitest/instrumentation_spec.rb | 34 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/datadog/ci/contrib/minitest/hooks.rb b/lib/datadog/ci/contrib/minitest/hooks.rb index 84a4c07f..c635c0ab 100644 --- a/lib/datadog/ci/contrib/minitest/hooks.rb +++ b/lib/datadog/ci/contrib/minitest/hooks.rb @@ -14,8 +14,6 @@ def before_setup super return unless datadog_configuration[:enabled] - test_name = "#{class_name}##{name}" - test_suite_name = Helpers.test_suite_name(self.class, name) if Helpers.parallel?(self.class) test_suite_name = "#{test_suite_name} (#{name} concurrently)" @@ -27,7 +25,7 @@ def before_setup source_file, line_number = method(name).source_location CI.start_test( - test_name, + name, test_suite_name, tags: { CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, diff --git a/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb b/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb index 9d866533..ec36a54e 100644 --- a/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb @@ -33,10 +33,10 @@ def test_foo klass.new(:test_foo).run expect(span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST) - expect(span.name).to eq("SomeTest#test_foo") - expect(span.resource).to eq("SomeTest#test_foo") + expect(span.name).to eq("test_foo") + expect(span.resource).to eq("test_foo") expect(span.service).to eq("ltest") - expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeTest#test_foo") + expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("test_foo") expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq( "SomeTest at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb" ) @@ -92,9 +92,9 @@ def self.name klass.new(method_name).run expect(span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST) - expect(span.resource).to eq("SomeSpec##{method_name}") + expect(span.resource).to eq(method_name) expect(span.service).to eq("ltest") - expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeSpec##{method_name}") + expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq(method_name) expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq( "SomeSpec at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb" ) @@ -496,7 +496,7 @@ def test_fail end it "traces test, test session, test module with failed status" do - expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeFailedTest#test_fail") + expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("test_fail") expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq( Datadog::CI::Ext::Test::Status::FAIL ) @@ -538,21 +538,19 @@ class SomeSpec < Minitest::Spec end end - it "traces tests with unique names" do + it "traces tests with the same name but different test suites" do test_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_NAME) }.sort expect(test_names).to eq( [ - "SomeSpec#test_0001_does not fail", - "in context#test_0001_does not fail", - "in context::deeper context#test_0001_does not fail", - "in other context#test_0001_does not fail" + "test_0001_does not fail", + "test_0001_does not fail", + "test_0001_does not fail", + "test_0001_does not fail" ] ) - end - - it "connects tests to different test suites (one per spec context)" do test_suite_ids = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq + test_suite_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort expect(test_suite_ids).to have(4).items @@ -617,10 +615,10 @@ def test_b_2 test_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_NAME) }.sort expect(test_names).to eq( [ - "TestA#test_a_1", - "TestA#test_a_2", - "TestB#test_b_1", - "TestB#test_b_2" + "test_a_1", + "test_a_2", + "test_b_1", + "test_b_2" ] )