-
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.
add datadog ci plugin and reporter for minitest to track test session…
… start/end events
- Loading branch information
1 parent
bfbdb51
commit 14eb7c2
Showing
11 changed files
with
201 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
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,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 | ||
|
||
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) | ||
|
||
# we create dynamic class here to avoid referencing ::Minitest constant | ||
# in datadog-ci class definitions because Minitest is not always available | ||
datadog_reporter_klass = Class.new(::Minitest::AbstractReporter) do | ||
def initialize(reporter) | ||
# This creates circular reference as reporter holds reference to this reporter. | ||
# To make sure that reporter can be garbage collected, we use WeakRef. | ||
@reporter = WeakRef.new(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 | ||
end | ||
end | ||
|
||
reporter.reporters << datadog_reporter_klass.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
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 Plugin | ||
def self.included: (untyped base) -> untyped | ||
|
||
module ClassMethods | ||
attr_reader reporter: WeakRef | ||
@reporter: WeakRef | ||
|
||
def plugin_datadog_ci_init: (*untyped) -> (nil | untyped) | ||
|
||
def initialize: (untyped reporter) -> void | ||
|
||
def report: () -> (nil | untyped) | ||
|
||
private | ||
|
||
def datadog_configuration: () -> untyped | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# as rbs misses delegator support, we make WeakRef a subclass of CompositeReporter | ||
# for our current use case | ||
class WeakRef < Minitest::CompositeReporter | ||
def initialize: (untyped obj) -> untyped | ||
def weakref_alive?: () -> bool | ||
end |