diff --git a/lib/datadog/ci/contrib/minitest/reporter.rb b/lib/datadog/ci/contrib/minitest/reporter.rb index 2de6eb7d..bc0e1096 100644 --- a/lib/datadog/ci/contrib/minitest/reporter.rb +++ b/lib/datadog/ci/contrib/minitest/reporter.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "weakref" - require_relative "../../ext/test" require_relative "ext" diff --git a/lib/datadog/ci/contrib/rspec/example.rb b/lib/datadog/ci/contrib/rspec/example.rb index 598cc860..f495a724 100644 --- a/lib/datadog/ci/contrib/rspec/example.rb +++ b/lib/datadog/ci/contrib/rspec/example.rb @@ -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, @@ -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 @@ -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 diff --git a/lib/datadog/ci/contrib/rspec/patcher.rb b/lib/datadog/ci/contrib/rspec/patcher.rb index bf8ca049..7019ffbf 100644 --- a/lib/datadog/ci/contrib/rspec/patcher.rb +++ b/lib/datadog/ci/contrib/rspec/patcher.rb @@ -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 diff --git a/sig/datadog/ci/contrib/rspec/example.rbs b/sig/datadog/ci/contrib/rspec/example.rbs index 5acf73bd..fbce84bb 100644 --- a/sig/datadog/ci/contrib/rspec/example.rbs +++ b/sig/datadog/ci/contrib/rspec/example.rbs @@ -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 diff --git a/sig/datadog/ci/contrib/rspec/patcher.rbs b/sig/datadog/ci/contrib/rspec/patcher.rbs index ef9ba05d..47443508 100644 --- a/sig/datadog/ci/contrib/rspec/patcher.rbs +++ b/sig/datadog/ci/contrib/rspec/patcher.rbs @@ -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 diff --git a/vendor/rbs/rspec/0/rspec.rbs b/vendor/rbs/rspec/0/rspec.rbs index 7ad75247..5ccb0357 100644 --- a/vendor/rbs/rspec/0/rspec.rbs +++ b/vendor/rbs/rspec/0/rspec.rbs @@ -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