Skip to content

Commit

Permalink
minitest instrumentation doesn't use public API anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 26, 2024
1 parent 7a41b72 commit 6713cc0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/datadog/ci/contrib/minitest/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run(*args)

test_suite_name = Helpers.test_suite_name(self, method)

test_suite = Datadog::CI.start_test_suite(test_suite_name)
test_suite = test_visibility_component.start_test_suite(test_suite_name)

results = super
return results unless test_suite
Expand All @@ -34,6 +34,10 @@ def run(*args)
def datadog_configuration
Datadog.configuration.ci[:minitest]
end

def test_visibility_component
Datadog.send(:components).test_visibility
end
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/datadog/ci/contrib/minitest/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ def init_plugins(*args)

return unless datadog_configuration[:enabled]

CI.start_test_session(
test_visibility_component.start_test_session(
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s
},
service: datadog_configuration[:service_name]
)
CI.start_test_module(Ext::FRAMEWORK)
test_visibility_component.start_test_module(Ext::FRAMEWORK)
end

private

def datadog_configuration
Datadog.configuration.ci[:minitest]
end

def test_visibility_component
Datadog.send(:components).test_visibility
end
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/datadog/ci/contrib/minitest/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def before_setup
test_suite_name = "#{test_suite_name} (#{name} concurrently)"

# for parallel execution we need to start a new test suite for each test
CI.start_test_suite(test_suite_name)
test_visibility_component.start_test_suite(test_suite_name)
end

source_file, line_number = method(name).source_location

test_span = CI.start_test(
test_span = test_visibility_component.trace_test(
name,
test_suite_name,
tags: {
Expand All @@ -47,7 +47,7 @@ def before_setup
end

def after_teardown
test_span = CI.active_test
test_span = test_visibility_component.active_test
return super unless test_span

finish_with_result(test_span, result_code)
Expand Down Expand Up @@ -77,6 +77,10 @@ def finish_with_result(span, result_code)
def datadog_configuration
Datadog.configuration.ci[:minitest]
end

def test_visibility_component
Datadog.send(:components).test_visibility
end
end

module ClassMethods
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/minitest/runnable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Datadog
def test_order: () -> (nil | :parallel | :random | :sorted | :alpha)

def runnable_methods: () -> Array[String]

def test_visibility_component: () -> Datadog::CI::TestVisibility::Component
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/minitest/runner.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Datadog
private

def datadog_configuration: () -> untyped

def test_visibility_component: () -> Datadog::CI::TestVisibility::Component
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/minitest/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Datadog

def datadog_configuration: () -> untyped

def test_visibility_component: () -> Datadog::CI::TestVisibility::Component

def finish_with_result: (Datadog::CI::Span? span, String result_code) -> void
end
end
Expand Down
10 changes: 9 additions & 1 deletion spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ module Kernel
end

RSpec.describe "Minitest instrumentation" do
before do
# expect that public manual API isn't used
expect(Datadog::CI).to receive(:start_test_session).never
expect(Datadog::CI).to receive(:start_test_module).never
expect(Datadog::CI).to receive(:start_test_suite).never
expect(Datadog::CI).to receive(:start_test).never
end

context "without service name configured" do
include_context "CI mode activated" do
let(:integration_name) { :minitest }
Expand Down Expand Up @@ -78,7 +86,7 @@ def test_foo
:source_file,
"spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
expect(span).to have_test_tag(:source_start, "51")
expect(span).to have_test_tag(:source_start, "59")
expect(span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down

0 comments on commit 6713cc0

Please sign in to comment.