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
Instance Attribute Summary collapse
-
#logical_test_session_name ⇒ Object
readonly
Returns the value of attribute logical_test_session_name.
-
#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, logical_test_session_name: nil) ⇒ Component
constructor
A new instance of Component.
- #itr_enabled? ⇒ Boolean
- #shutdown! ⇒ Object
- #start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
- #start_test_session(service: nil, tags: {}, total_tests_count: 0) ⇒ 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, logical_test_session_name: nil) ⇒ Component
Returns a new instance of Component.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 23 def initialize( test_suite_level_visibility_enabled: false, codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse, logical_test_session_name: nil ) @test_suite_level_visibility_enabled = test_suite_level_visibility_enabled @context = Context.new @codeowners = codeowners @logical_test_session_name = logical_test_session_name end |
Instance Attribute Details
#logical_test_session_name ⇒ Object (readonly)
Returns the value of attribute logical_test_session_name.
21 22 23 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 21 def logical_test_session_name @logical_test_session_name end |
#test_suite_level_visibility_enabled ⇒ Object (readonly)
Returns the value of attribute test_suite_level_visibility_enabled.
21 22 23 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 21 def test_suite_level_visibility_enabled @test_suite_level_visibility_enabled end |
Instance Method Details
#active_span ⇒ Object
88 89 90 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 88 def active_span @context.active_span end |
#active_test ⇒ Object
92 93 94 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 92 def active_test @context.active_test end |
#active_test_module ⇒ Object
100 101 102 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 100 def active_test_module @context.active_test_module end |
#active_test_session ⇒ Object
96 97 98 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 96 def active_test_session @context.active_test_session end |
#active_test_suite(test_suite_name) ⇒ Object
104 105 106 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 104 def active_test_suite(test_suite_name) @context.active_test_suite(test_suite_name) end |
#deactivate_test ⇒ Object
108 109 110 111 112 113 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 108 def deactivate_test test = active_test on_test_finished(test) if test @context.deactivate_test end |
#deactivate_test_module ⇒ Object
122 123 124 125 126 127 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 122 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
115 116 117 118 119 120 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 115 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
129 130 131 132 133 134 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 129 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
136 137 138 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 136 def itr_enabled? test_optimisation.enabled? end |
#shutdown! ⇒ Object
140 141 142 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 140 def shutdown! # noop, there is no thread owned by test visibility component end |
#start_test_module(test_module_name, service: nil, tags: {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 44 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: {}, total_tests_count: 0) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 34 def start_test_session(service: nil, tags: {}, total_tests_count: 0) return skip_tracing unless test_suite_level_visibility_enabled test_session = @context.start_test_session(service: service, tags: ) test_session.total_tests_count = total_tests_count on_test_session_started(test_session) test_session end |
#start_test_suite(test_suite_name, service: nil, tags: {}) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 52 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
78 79 80 81 82 83 84 85 86 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 78 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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/datadog/ci/test_visibility/component.rb', line 60 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| subscribe_to_after_stop_event(test.tracer_span) 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: ) subscribe_to_after_stop_event(test.tracer_span) on_test_started(test) test end end |