diff --git a/lib/datadog/ci.rb b/lib/datadog/ci.rb index a3ddfd04..2720ad23 100644 --- a/lib/datadog/ci.rb +++ b/lib/datadog/ci.rb @@ -414,6 +414,7 @@ def test_optimisation # Test runners (instrumented automatically when corresponding frameworks are instrumented) require_relative "ci/contrib/knapsack/integration" +require_relative "ci/contrib/ciqueue/integration" # Additional test libraries (auto instrumented later on test session start) require_relative "ci/contrib/selenium/integration" diff --git a/lib/datadog/ci/contrib/ciqueue/integration.rb b/lib/datadog/ci/contrib/ciqueue/integration.rb new file mode 100644 index 00000000..6a534945 --- /dev/null +++ b/lib/datadog/ci/contrib/ciqueue/integration.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require_relative "../integration" +require_relative "patcher" + +module Datadog + module CI + module Contrib + module Ciqueue + # ci-queue test runner instrumentation + # https://github.com/Shopify/ci-queue + class Integration < Contrib::Integration + MINIMUM_VERSION = Gem::Version.new("0.9.0") + + def version + Gem.loaded_specs["ci-queue"]&.version + end + + def loaded? + !defined?(::RSpec::Queue::Runner).nil? + end + + def compatible? + super && version >= MINIMUM_VERSION + end + + def patcher + Patcher + end + end + end + end + end +end diff --git a/lib/datadog/ci/contrib/ciqueue/patcher.rb b/lib/datadog/ci/contrib/ciqueue/patcher.rb new file mode 100644 index 00000000..82651f01 --- /dev/null +++ b/lib/datadog/ci/contrib/ciqueue/patcher.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require_relative "../patcher" +require_relative "../rspec/runner" + +module Datadog + module CI + module Contrib + module Ciqueue + # Patcher enables patching of 'rspec' module. + module Patcher + include Datadog::CI::Contrib::Patcher + + module_function + + def patch + ::RSpec::Queue::Runner.include(Contrib::RSpec::Runner) + end + end + end + end + end +end diff --git a/lib/datadog/ci/contrib/rspec/integration.rb b/lib/datadog/ci/contrib/rspec/integration.rb index 6403e5c4..6483c73d 100644 --- a/lib/datadog/ci/contrib/rspec/integration.rb +++ b/lib/datadog/ci/contrib/rspec/integration.rb @@ -13,7 +13,7 @@ class Integration < Contrib::Integration MINIMUM_VERSION = Gem::Version.new("3.0.0") def dependants - %i[knapsack] + %i[knapsack ciqueue] end def version diff --git a/lib/datadog/ci/contrib/rspec/patcher.rb b/lib/datadog/ci/contrib/rspec/patcher.rb index 116d2040..611b8a15 100644 --- a/lib/datadog/ci/contrib/rspec/patcher.rb +++ b/lib/datadog/ci/contrib/rspec/patcher.rb @@ -17,23 +17,10 @@ module Patcher module_function def patch - # ci-queue test runner instrumentation - # TODO: to be extracted in the next PR - # https://github.com/Shopify/ci-queue - if ci_queue? - ::RSpec::Queue::Runner.include(Runner) - end - - # default rspec test runner instrumentation ::RSpec::Core::Runner.include(Runner) - ::RSpec::Core::Example.include(Example) ::RSpec::Core::ExampleGroup.include(ExampleGroup) end - - def ci_queue? - !!defined?(::RSpec::Queue::Runner) - end end end end diff --git a/sig/datadog/ci/contrib/ciqueue/integration.rbs b/sig/datadog/ci/contrib/ciqueue/integration.rbs new file mode 100644 index 00000000..f645edde --- /dev/null +++ b/sig/datadog/ci/contrib/ciqueue/integration.rbs @@ -0,0 +1,19 @@ +module Datadog + module CI + module Contrib + module Ciqueue + class Integration < Contrib::Integration + MINIMUM_VERSION: untyped + + def version: () -> untyped + + def loaded?: () -> bool + + def compatible?: () -> bool + + def patcher: () -> singleton(Patcher) + end + end + end + end +end diff --git a/sig/datadog/ci/contrib/ciqueue/patcher.rbs b/sig/datadog/ci/contrib/ciqueue/patcher.rbs new file mode 100644 index 00000000..4519f467 --- /dev/null +++ b/sig/datadog/ci/contrib/ciqueue/patcher.rbs @@ -0,0 +1,13 @@ +module Datadog + module CI + module Contrib + module Ciqueue + module Patcher + include Datadog::CI::Contrib::Patcher + + def self?.patch: () -> void + end + end + end + end +end