Skip to content

Commit

Permalink
rspec 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 6713cc0 commit 202e792
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def run(*args)

if ci_queue?
suite_name = "#{suite_name} (ci-queue running example [#{test_name}])"
test_suite_span = CI.start_test_suite(suite_name)
test_suite_span = test_visibility_component.start_test_suite(suite_name)
end

CI.trace_test(
test_visibility_component.trace_test(
test_name,
suite_name,
tags: {
Expand Down Expand Up @@ -99,6 +99,10 @@ def datadog_configuration
Datadog.configuration.ci[:rspec]
end

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

def ci_queue?
!!defined?(::RSpec::Queue::ExampleExtension) &&
self.class.ancestors.include?(::RSpec::Queue::ExampleExtension)
Expand Down
6 changes: 5 additions & 1 deletion lib/datadog/ci/contrib/rspec/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run(reporter = ::RSpec::Core::NullReporter)
return super unless top_level?

suite_name = "#{description} at #{file_path}"
test_suite = Datadog::CI.start_test_suite(suite_name)
test_suite = test_visibility_component.start_test_suite(suite_name)

success = super
return success unless test_suite
Expand All @@ -44,6 +44,10 @@ def run(reporter = ::RSpec::Core::NullReporter)
def datadog_configuration
Datadog.configuration.ci[:rspec]
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/rspec/knapsack_pro/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def knapsack__run_specs(*args)
return super if ::RSpec.configuration.dry_run?
return super unless datadog_configuration[:enabled]

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

test_module = CI.start_test_module(Ext::FRAMEWORK)
test_module = test_visibility_component.start_test_module(Ext::FRAMEWORK)

result = super
return result unless test_module && test_session
Expand All @@ -49,6 +49,10 @@ def knapsack__run_specs(*args)
def datadog_configuration
Datadog.configuration.ci[:rspec]
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/rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def run_specs(*args)
return super if ::RSpec.configuration.dry_run?
return super unless datadog_configuration[:enabled]

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

test_module = CI.start_test_module(Ext::FRAMEWORK)
test_module = test_visibility_component.start_test_module(Ext::FRAMEWORK)

result = super
return result unless test_module && test_session
Expand All @@ -49,6 +49,10 @@ def run_specs(*args)
def datadog_configuration
Datadog.configuration.ci[:rspec]
end

def test_visibility_component
Datadog.send(:components).test_visibility
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/ci/contrib/rspec/example.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Datadog

def fetch_top_level_example_group: () -> Hash[Symbol, untyped]
def datadog_configuration: () -> untyped
def test_visibility_component: () -> Datadog::CI::TestVisibility::Component
def ci_queue?: () -> bool
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/rspec/example_group.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/rspec/knapsack_pro/runner.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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/rspec/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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
require "securerandom"

RSpec.describe "RSpec instrumentation with Shopify's ci-queue runner" 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

include_context "CI mode activated" do
let(:integration_name) { :rspec }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
require "fileutils"

RSpec.describe "RSpec instrumentation with Knapsack Pro runner in queue mode" 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

include_context "CI mode activated" do
let(:integration_name) { :rspec }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
require "fileutils"

RSpec.describe "Knapsack Pro runner when Datadog::CI is configured during the knapsack run like in rspec_go rake task" 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

# Yields to a block in a new RSpec global context. All RSpec
# test configuration and execution should be wrapped in this method.
def with_new_rspec_environment
Expand Down
10 changes: 9 additions & 1 deletion spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require "time"

RSpec.describe "RSpec hooks" 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

# Yields to a block in a new RSpec global context. All RSpec
# test configuration and execution should be wrapped in this method.
def with_new_rspec_environment
Expand Down Expand Up @@ -109,7 +117,7 @@ def rspec_session_run(
:source_file,
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_span).to have_test_tag(:source_start, "82")
expect(first_test_span).to have_test_tag(:source_start, "90")
expect(first_test_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down

0 comments on commit 202e792

Please sign in to comment.