Skip to content

Commit

Permalink
ci-queue support for rspec instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 23, 2024
1 parent c3ccfee commit 20bc8af
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/datadog/ci/contrib/minitest/reporter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "weakref"

require_relative "../../ext/test"
require_relative "ext"

Expand Down
26 changes: 24 additions & 2 deletions lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def run(*)
test_suite_description = fetch_top_level_example_group[:description]
suite_name = "#{test_suite_description} at #{metadata[:example_group][:rerun_file_path]}"

# remove suite name from test name to avoid duplication
# remove example group description from test name to avoid duplication
test_name = test_name.sub(test_suite_description, "").strip

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

CI.trace_test(
test_name,
suite_name,
Expand All @@ -49,13 +54,25 @@ def run(*)
case execution_result.status
when :passed
test_span.passed!
test_suite_span.passed! if test_suite_span
when :failed
test_span.failed!(exception: execution_result.exception)
test_suite_span.failed! if test_suite_span
else
test_span.skipped!(exception: execution_result.exception) if execution_result.example_skipped?
# :pending or nil
if execution_result.pending_message
test_span.skipped!(reason: execution_result.pending_message)
elsif execution_result.example_skipped?
test_span.skipped!(exception: execution_result.exception)
else
test_span.skipped!(exception: execution_result.pending_exception)
end
test_suite_span.skipped! if test_suite_span
end
end

test_suite_span.finish if test_suite_span

result
end
end
Expand All @@ -75,6 +92,11 @@ def fetch_top_level_example_group
def datadog_configuration
Datadog.configuration.ci[:rspec]
end

def ci_queue?
defined?(::RSpec::Queue::ExampleExtension) &&
self.class.ancestors.include?(::RSpec::Queue::ExampleExtension)
end
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion lib/datadog/ci/contrib/rspec/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ def target_version
end

def patch
::RSpec::Core::Example.include(Example)
if ci_queue?
::RSpec::Queue::Runner.include(Runner)
end

::RSpec::Core::Runner.include(Runner)
::RSpec::Core::Example.include(Example)
::RSpec::Core::ExampleGroup.include(ExampleGroup)
end

def ci_queue?
# ::RSpec::Queue::Runner is a ci-queue runner
defined?(::RSpec::Queue::Runner)
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 ci_queue?: () -> bool
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions sig/datadog/ci/contrib/rspec/patcher.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module Datadog
module Patcher
include Datadog::Tracing::Contrib::Patcher

def self?.target_version: () -> untyped
def self?.target_version: () -> String

def self?.patch: () -> untyped
def self?.patch: () -> void

def self?.ci_queue?: () -> bool
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions vendor/rbs/rspec/0/rspec.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ end
module RSpec::Core
end

module RSpec::Queue
end

module RSpec::Queue::Runner
end

module RSpec::Queue::ExampleExtension
end

module RSpec::Core::Example
def run: () -> untyped
def execution_result: () -> untyped
Expand Down

0 comments on commit 20bc8af

Please sign in to comment.