Skip to content

Commit

Permalink
Merge pull request #254 from DataDog/anmarchenko/ci_queue_standalone_…
Browse files Browse the repository at this point in the history
…integration

[SDTEST-1129] extract ciqueue instrumentation
  • Loading branch information
anmarchenko authored Nov 19, 2024
2 parents 4aae21e + 5c551e7 commit 9c8d52b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions lib/datadog/ci/contrib/ciqueue/integration.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions lib/datadog/ci/contrib/ciqueue/patcher.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/rspec/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions lib/datadog/ci/contrib/rspec/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions sig/datadog/ci/contrib/ciqueue/integration.rbs
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions sig/datadog/ci/contrib/ciqueue/patcher.rbs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9c8d52b

Please sign in to comment.