Class: Datadog::CI::TestVisibility::Component
- Inherits:
-
Object
- Object
- Datadog::CI::TestVisibility::Component
- Defined in:
- lib/datadog/ci/test_visibility/component.rb
Overview
Common behavior for CI tests
Constant Summary collapse
- FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY =
:__dd_test_finished_callback
Instance Attribute Summary collapse
-
#test_suite_level_visibility_enabled ⇒ Object
readonly
Returns the value of attribute test_suite_level_visibility_enabled.
Instance Method Summary collapse
- #active_span ⇒ Object
- #active_test ⇒ Object
- #active_test_module ⇒ Object
- #active_test_session ⇒ Object
- #active_test_suite(test_suite_name) ⇒ Object
- #deactivate_test ⇒ Object
- #deactivate_test_module ⇒ Object
- #deactivate_test_session ⇒ Object
- #deactivate_test_suite(test_suite_name) ⇒ Object
-
#initialize(test_suite_level_visibility_enabled: false, codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse) ⇒ Component
constructor
A new instance of Component.
- #itr_enabled? ⇒ Boolean
- #remove_test_finished_callback ⇒ Object
-
#set_test_finished_callback(callback) ⇒ Object
sets fiber-local callback to be called when test is finished.
- #shutdown! ⇒ Object
- #start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
- #start_test_session(service: nil, tags: {}) ⇒ Object
- #start_test_suite(test_suite_name, service: nil, tags: {}) ⇒ Object
- #trace(span_name, type: "span", tags: {}, &block) ⇒ Object
- #trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) ⇒ Object
Constructor Details
#initialize(test_suite_level_visibility_enabled: false, codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse) ⇒ Component
Returns a new instance of Component.
24 25 26 27 28 29 30 31 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 24 def initialize( test_suite_level_visibility_enabled: false, codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse ) @test_suite_level_visibility_enabled = test_suite_level_visibility_enabled @context = Context.new @codeowners = codeowners end |
Instance Attribute Details
#test_suite_level_visibility_enabled ⇒ Object (readonly)
Returns the value of attribute test_suite_level_visibility_enabled.
20 21 22 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 20 def test_suite_level_visibility_enabled @test_suite_level_visibility_enabled end |
Instance Method Details
#active_span ⇒ Object
82 83 84 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 82 def active_span @context.active_span end |
#active_test ⇒ Object
86 87 88 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 86 def active_test @context.active_test end |
#active_test_module ⇒ Object
94 95 96 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 94 def active_test_module @context.active_test_module end |
#active_test_session ⇒ Object
90 91 92 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 90 def active_test_session @context.active_test_session end |
#active_test_suite(test_suite_name) ⇒ Object
98 99 100 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 98 def active_test_suite(test_suite_name) @context.active_test_suite(test_suite_name) end |
#deactivate_test ⇒ Object
102 103 104 105 106 107 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 102 def deactivate_test test = active_test on_test_finished(test) if test @context.deactivate_test end |
#deactivate_test_module ⇒ Object
116 117 118 119 120 121 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 116 def deactivate_test_module test_module = active_test_module on_test_module_finished(test_module) if test_module @context.deactivate_test_module end |
#deactivate_test_session ⇒ Object
109 110 111 112 113 114 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 109 def deactivate_test_session test_session = active_test_session on_test_session_finished(test_session) if test_session @context.deactivate_test_session end |
#deactivate_test_suite(test_suite_name) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 123 def deactivate_test_suite(test_suite_name) test_suite = active_test_suite(test_suite_name) on_test_suite_finished(test_suite) if test_suite @context.deactivate_test_suite(test_suite_name) end |
#itr_enabled? ⇒ Boolean
139 140 141 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 139 def itr_enabled? test_optimisation.enabled? end |
#remove_test_finished_callback ⇒ Object
135 136 137 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 135 def remove_test_finished_callback Thread.current[FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY] = nil end |
#set_test_finished_callback(callback) ⇒ Object
sets fiber-local callback to be called when test is finished
131 132 133 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 131 def set_test_finished_callback(callback) Thread.current[FIBER_LOCAL_TEST_FINISHED_CALLBACK_KEY] = callback end |
#shutdown! ⇒ Object
143 144 145 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 143 def shutdown! # noop, there is no thread owned by test visibility component end |
#start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 41 def start_test_module(test_module_name, service: nil, tags: {}) return skip_tracing unless test_suite_level_visibility_enabled test_module = @context.start_test_module(test_module_name, service: service, tags: ) on_test_module_started(test_module) test_module end |
#start_test_session(service: nil, tags: {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 33 def start_test_session(service: nil, tags: {}) return skip_tracing unless test_suite_level_visibility_enabled test_session = @context.start_test_session(service: service, tags: ) on_test_session_started(test_session) test_session end |
#start_test_suite(test_suite_name, service: nil, tags: {}) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 49 def start_test_suite(test_suite_name, service: nil, tags: {}) return skip_tracing unless test_suite_level_visibility_enabled test_suite = @context.start_test_suite(test_suite_name, service: service, tags: ) on_test_suite_started(test_suite) test_suite end |
#trace(span_name, type: "span", tags: {}, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 72 def trace(span_name, type: "span", tags: {}, &block) if block @context.trace(span_name, type: type, tags: ) do |span| block.call(span) end else @context.trace(span_name, type: type, tags: ) end end |
#trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 57 def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block) if block @context.trace_test(test_name, test_suite_name, service: service, tags: ) do |test| on_test_started(test) res = block.call(test) on_test_finished(test) res end else test = @context.trace_test(test_name, test_suite_name, service: service, tags: ) on_test_started(test) test end end |