-
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.
Merge pull request #92 from DataDog/anmarchenko/minitest_tslv_instrum…
…entation [CIVIS-7948] Test suite level visibility instrumentation for Minitest framework
- Loading branch information
Showing
26 changed files
with
768 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ target :lib do | |
library "rspec" | ||
library "cucumber" | ||
library "msgpack" | ||
library "weakref" | ||
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
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Helpers | ||
def self.test_suite_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 | ||
|
||
def self.parallel?(klass) | ||
klass.ancestors.include?(::Minitest::Parallel::Test) | ||
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
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "weakref" | ||
|
||
require_relative "../../ext/test" | ||
require_relative "ext" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Plugin | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
class DatadogReporter < ::Minitest::AbstractReporter | ||
def initialize(minitest_reporter) | ||
# This creates circular reference as minitest_reporter also holds reference to DatadogReporter. | ||
# To make sure that minitest_reporter can be garbage collected, we use WeakRef. | ||
@reporter = WeakRef.new(minitest_reporter) | ||
end | ||
|
||
def report | ||
active_test_session = CI.active_test_session | ||
active_test_module = CI.active_test_module | ||
|
||
return unless @reporter.weakref_alive? | ||
return if active_test_session.nil? || active_test_module.nil? | ||
|
||
if @reporter.passed? | ||
active_test_module.passed! | ||
active_test_session.passed! | ||
else | ||
active_test_module.failed! | ||
active_test_session.failed! | ||
end | ||
|
||
active_test_module.finish | ||
active_test_session.finish | ||
|
||
nil | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def plugin_datadog_ci_init(*) | ||
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, | ||
CI::Ext::Test::TAG_TYPE => CI::Ext::Test::TEST_TYPE | ||
}, | ||
service: datadog_configuration[:service_name] | ||
) | ||
CI.start_test_module(test_session.name) | ||
|
||
reporter.reporters << DatadogReporter.new(reporter) | ||
end | ||
|
||
private | ||
|
||
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,42 @@ | ||
require_relative "helpers" | ||
|
||
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 Helpers.parallel?(self) | ||
|
||
method = runnable_methods.first | ||
return super if method.nil? | ||
|
||
test_suite_name = Helpers.test_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 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
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
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
Oops, something went wrong.