-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instrument Minitest::Runnable to trace test suites for serial execution
- Loading branch information
1 parent
5c53f85
commit 17e5dc6
Showing
8 changed files
with
195 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require_relative "suite" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Runnable | ||
def self.included(base) | ||
base.singleton_class.prepend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def run(*) | ||
return super unless datadog_configuration[:enabled] | ||
return super if parallel? | ||
return super if runnable_methods.empty? | ||
|
||
method = runnable_methods.first | ||
test_suite_name = Suite.name(self, method) | ||
|
||
test_suite = Datadog::CI.start_test_suite(test_suite_name) | ||
test_suite.passed! # will be overridden if any test fails | ||
|
||
results = super | ||
|
||
test_suite.finish | ||
|
||
results | ||
end | ||
|
||
private | ||
|
||
def parallel? | ||
test_order == :parallel | ||
end | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:minitest] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
# Minitest integration constants | ||
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes. | ||
module Suite | ||
def self.name(klass, method_name) | ||
source_location, = klass.instance_method(method_name).source_location | ||
source_file_path = Pathname.new(source_location.to_s).relative_path_from(Pathname.pwd).to_s | ||
|
||
"#{klass.name} at #{source_file_path}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Runnable | ||
def self.included: (untyped base) -> untyped | ||
|
||
module ClassMethods : ::Minitest::Runnable | ||
|
||
def run: (*untyped) -> untyped | ||
|
||
private | ||
|
||
def parallel?: () -> bool | ||
|
||
def datadog_configuration: () -> untyped | ||
|
||
def test_order: () -> (nil | :parallel | :random | :sorted | :alpha) | ||
|
||
def runnable_methods: () -> Array[String] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Suite | ||
def self.name: (untyped klass, String? method_name) -> ::String | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters