Skip to content

Commit

Permalink
minitest: start test session and test module in Minitest#init_plugins…
Browse files Browse the repository at this point in the history
… method as it is executed before start of parallel_executor and will propagate global context to forked rails workers
  • Loading branch information
anmarchenko committed Jan 25, 2024
1 parent 9acd580 commit d255285
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
10 changes: 8 additions & 2 deletions lib/datadog/ci/contrib/minitest/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative "runner"
require_relative "reporter"
require_relative "hooks"
require_relative "runnable"
Expand All @@ -19,9 +20,14 @@ def target_version
end

def patch
::Minitest::CompositeReporter.include(Reporter)
::Minitest::Test.include(Hooks)
# test session start
::Minitest.include(Runner)
# test suites (when not executed concurrently)
::Minitest::Runnable.include(Runnable)
# tests; test suites (when executed concurrently)
::Minitest::Test.include(Hooks)
# test session finish
::Minitest::CompositeReporter.include(Reporter)
end
end
end
Expand Down
15 changes: 0 additions & 15 deletions lib/datadog/ci/contrib/minitest/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ def report(*)
res
end

def start(*)
return super unless datadog_configuration[:enabled]

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

super
end

private

def datadog_configuration
Expand Down
41 changes: 41 additions & 0 deletions lib/datadog/ci/contrib/minitest/runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

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

module Datadog
module CI
module Contrib
module Minitest
module Runner
def self.included(base)
base.singleton_class.prepend(ClassMethods)
end

module ClassMethods
def init_plugins(*)
super

return unless datadog_configuration[:enabled]

test_session = CI.start_test_session(
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s
},
service: datadog_configuration[:service_name]
)
CI.start_test_module(test_session.name) if test_session
end

private

def datadog_configuration
Datadog.configuration.ci[:minitest]
end
end
end
end
end
end
end
2 changes: 0 additions & 2 deletions sig/datadog/ci/contrib/minitest/reporter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Datadog
class InstanceMethods < ::Minitest::AbstractReporter
def report: (*untyped) -> untyped

def start: (*untyped) -> untyped

private

def datadog_configuration: () -> untyped
Expand Down
21 changes: 21 additions & 0 deletions sig/datadog/ci/contrib/minitest/runner.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Datadog
module CI
module Contrib
module Minitest
module Runner
def self.included: (untyped base) -> untyped

class ClassMethods
extend ::Minitest

def init_plugins: (*untyped) -> (nil | untyped)

private

def datadog_configuration: () -> untyped
end
end
end
end
end
end

0 comments on commit d255285

Please sign in to comment.