Class: Datadog::CI::Test
Overview
Represents a single part of a test run.
Instance Attribute Summary
Attributes inherited from Span
Instance Method Summary collapse
- #all_executions_failed? ⇒ Boolean
- #all_executions_passed? ⇒ Boolean
- #any_retry_passed? ⇒ Boolean
-
#attempt_to_fix? ⇒ Boolean
Returns "true" if this flaky test has fixing attempts (determined by Datadog backend).
- #datadog_skip_reason ⇒ Object
-
#datadog_test_id ⇒ String
The test id according to Datadog's test impact analysis.
-
#disabled? ⇒ Boolean
Returns "true" if this test is disabled by Datadog test management.
-
#end_line ⇒ Integer?
Returns the ending line number of the test in the source file.
-
#failed!(exception: nil) ⇒ void
Sets the status of the span to "fail".
-
#finish ⇒ void
Finishes the current test.
-
#is_new? ⇒ Boolean
Returns "true" if this span represents a test that wasn't known to Datadog before.
-
#is_retry? ⇒ Boolean
Returns "true" if test span represents a retry.
-
#itr_unskippable! ⇒ void
Marks this test as unskippable by the Test Impact Analysis.
-
#modified? ⇒ Boolean
Returns "true" if this test is marked as modified (e.g., impacted by code changes).
-
#name ⇒ String
The name of the test.
-
#parameters ⇒ String?
Gets the parameters for this test (e.g. Cucumber example or RSpec specs) as a serialized JSON.
-
#passed! ⇒ void
Sets the status of the span to "pass".
-
#quarantined? ⇒ Boolean
Returns "true" if this test is quarantined by Datadog test management.
-
#retry_reason ⇒ String
Returns string with a reason why test was retried.
-
#set_parameters(arguments, metadata = {}) ⇒ void
Sets the parameters for this test (e.g. Cucumber example or RSpec specs).
- #should_ignore_failures? ⇒ Boolean
- #should_skip? ⇒ Boolean
-
#skipped!(exception: nil, reason: nil) ⇒ void
Sets the status of the span to "skip".
- #skipped_by_test_impact_analysis? ⇒ Boolean
-
#start_line ⇒ Integer?
Returns the starting line number of the test in the source file.
-
#test_module_id ⇒ String
Span id of the running test module this test belongs to.
-
#test_session_id ⇒ String
Span id of the running test session this test belongs to.
-
#test_suite ⇒ Datadog::CI::TestSuite?
Running test suite that this test is part of (if any).
-
#test_suite_id ⇒ String
Span id of the running test suite this test belongs to.
-
#test_suite_name ⇒ String
Name of the running test suite this test belongs to.
Methods inherited from Span
#base_commit_sha, #clear_tag, #failed?, #get_metric, #get_tag, #git_branch, #git_commit_sha, #git_repository_url, #id, #initialize, #os_architecture, #os_platform, #os_version, #passed?, #runtime_name, #runtime_version, #service, #set_default_tags, #set_environment_runtime_tags, #set_metric, #set_tag, #set_tags, #skipped?, #source_file, #to_s, #trace_id, #type, #undefined?
Constructor Details
This class inherits a constructor from Datadog::CI::Span
Instance Method Details
#all_executions_failed? ⇒ Boolean
208 209 210 |
# File 'lib/datadog/ci/test.rb', line 208 def all_executions_failed? !!test_suite&.all_executions_failed?(datadog_test_id) end |
#all_executions_passed? ⇒ Boolean
213 214 215 |
# File 'lib/datadog/ci/test.rb', line 213 def all_executions_passed? !!test_suite&.all_executions_passed?(datadog_test_id) end |
#any_retry_passed? ⇒ Boolean
203 204 205 |
# File 'lib/datadog/ci/test.rb', line 203 def any_retry_passed? !!test_suite&.any_test_retry_passed?(datadog_test_id) end |
#attempt_to_fix? ⇒ Boolean
Returns "true" if this flaky test has fixing attempts (determined by Datadog backend).
117 118 119 |
# File 'lib/datadog/ci/test.rb', line 117 def attempt_to_fix? get_tag(Ext::Test::TAG_IS_ATTEMPT_TO_FIX) == "true" end |
#datadog_skip_reason ⇒ Object
218 219 220 221 222 223 224 |
# File 'lib/datadog/ci/test.rb', line 218 def datadog_skip_reason if skipped_by_test_impact_analysis? Ext::Test::SkipReason::TEST_IMPACT_ANALYSIS elsif disabled? || quarantined? Ext::Test::SkipReason::TEST_MANAGEMENT_DISABLED end end |
#datadog_test_id ⇒ String
Returns the test id according to Datadog's test impact analysis.
21 22 23 |
# File 'lib/datadog/ci/test.rb', line 21 def datadog_test_id @datadog_test_id ||= Utils::TestRun.datadog_test_id(name, test_suite_name, parameters) end |
#disabled? ⇒ Boolean
Returns "true" if this test is disabled by Datadog test management.
111 112 113 |
# File 'lib/datadog/ci/test.rb', line 111 def disabled? get_tag(Ext::Test::TAG_IS_TEST_DISABLED) == "true" end |
#end_line ⇒ Integer?
Returns the ending line number of the test in the source file.
80 81 82 83 |
# File 'lib/datadog/ci/test.rb', line 80 def end_line line = get_tag(Ext::Test::TAG_SOURCE_END) line&.to_i end |
#failed!(exception: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "fail".
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/datadog/ci/test.rb', line 160 def failed!(exception: nil) super # if we should ignore failures, we consider this test to be passed if should_ignore_failures? # use a special "fail_ignored" status to mark this test as failed but ignored record_test_result(Ext::Test::ExecutionStatsStatus::FAIL_IGNORED) else record_test_result(Ext::Test::Status::FAIL) end end |
#finish ⇒ void
This method returns an undefined value.
Finishes the current test.
27 28 29 30 31 32 33 34 35 |
# File 'lib/datadog/ci/test.rb', line 27 def finish if is_retry? && retry_reason.nil? set_tag(Ext::Test::TAG_RETRY_REASON, Ext::Test::RetryReason::RETRY_EXTERNAL) end test_visibility.deactivate_test super end |
#is_new? ⇒ Boolean
Returns "true" if this span represents a test that wasn't known to Datadog before.
99 100 101 |
# File 'lib/datadog/ci/test.rb', line 99 def is_new? get_tag(Ext::Test::TAG_IS_NEW) == "true" end |
#is_retry? ⇒ Boolean
Returns "true" if test span represents a retry.
87 88 89 |
# File 'lib/datadog/ci/test.rb', line 87 def is_retry? get_tag(Ext::Test::TAG_IS_RETRY) == "true" end |
#itr_unskippable! ⇒ void
This method returns an undefined value.
Marks this test as unskippable by the Test Impact Analysis. This must be done before the test execution starts.
Examples of tests that should be unskippable:
- tests that read files from disk
- tests that make network requests
- tests that call external processes
- tests that use forking
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/datadog/ci/test.rb', line 137 def itr_unskippable! TestOptimisation::Telemetry.itr_unskippable set_tag(Ext::Test::TAG_ITR_UNSKIPPABLE, "true") if skipped_by_test_impact_analysis? clear_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) TestOptimisation::Telemetry.itr_forced_run set_tag(Ext::Test::TAG_ITR_FORCED_RUN, "true") end end |
#modified? ⇒ Boolean
Returns "true" if this test is marked as modified (e.g., impacted by code changes).
123 124 125 |
# File 'lib/datadog/ci/test.rb', line 123 def modified? get_tag(Ext::Test::TAG_TEST_IS_MODIFIED) == "true" end |
#name ⇒ String
Returns the name of the test.
16 17 18 |
# File 'lib/datadog/ci/test.rb', line 16 def name get_tag(Ext::Test::TAG_NAME) end |
#parameters ⇒ String?
Gets the parameters for this test (e.g. Cucumber example or RSpec specs) as a serialized JSON.
198 199 200 |
# File 'lib/datadog/ci/test.rb', line 198 def parameters get_tag(Ext::Test::TAG_PARAMETERS) end |
#passed! ⇒ void
This method returns an undefined value.
Sets the status of the span to "pass".
151 152 153 154 155 |
# File 'lib/datadog/ci/test.rb', line 151 def passed! super record_test_result(Ext::Test::Status::PASS) end |
#quarantined? ⇒ Boolean
Returns "true" if this test is quarantined by Datadog test management.
105 106 107 |
# File 'lib/datadog/ci/test.rb', line 105 def quarantined? get_tag(Ext::Test::TAG_IS_QUARANTINED) == "true" end |
#retry_reason ⇒ String
Returns string with a reason why test was retried
93 94 95 |
# File 'lib/datadog/ci/test.rb', line 93 def retry_reason get_tag(Ext::Test::TAG_RETRY_REASON) end |
#set_parameters(arguments, metadata = {}) ⇒ void
This method returns an undefined value.
Sets the parameters for this test (e.g. Cucumber example or RSpec specs). Parameters are needed to compute test fingerprint to distinguish between different tests having same names.
188 189 190 191 192 |
# File 'lib/datadog/ci/test.rb', line 188 def set_parameters(arguments, = {}) return if arguments.nil? set_tag(Ext::Test::TAG_PARAMETERS, Utils::TestRun.test_parameters(arguments: arguments, metadata: )) end |
#should_ignore_failures? ⇒ Boolean
232 233 234 |
# File 'lib/datadog/ci/test.rb', line 232 def should_ignore_failures? quarantined? || disabled? || any_retry_passed? end |
#should_skip? ⇒ Boolean
227 228 229 |
# File 'lib/datadog/ci/test.rb', line 227 def should_skip? skipped_by_test_impact_analysis? || (disabled? && !attempt_to_fix?) end |
#skipped!(exception: nil, reason: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to "skip".
176 177 178 179 180 |
# File 'lib/datadog/ci/test.rb', line 176 def skipped!(exception: nil, reason: nil) super record_test_result(Ext::Test::Status::SKIP) end |
#skipped_by_test_impact_analysis? ⇒ Boolean
237 238 239 |
# File 'lib/datadog/ci/test.rb', line 237 def skipped_by_test_impact_analysis? get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true" end |
#start_line ⇒ Integer?
Returns the starting line number of the test in the source file.
72 73 74 75 |
# File 'lib/datadog/ci/test.rb', line 72 def start_line line = get_tag(Ext::Test::TAG_SOURCE_START) line&.to_i end |
#test_module_id ⇒ String
Span id of the running test module this test belongs to.
59 60 61 |
# File 'lib/datadog/ci/test.rb', line 59 def test_module_id get_tag(Ext::Test::TAG_TEST_MODULE_ID) end |
#test_session_id ⇒ String
Span id of the running test session this test belongs to.
65 66 67 |
# File 'lib/datadog/ci/test.rb', line 65 def test_session_id get_tag(Ext::Test::TAG_TEST_SESSION_ID) end |
#test_suite ⇒ Datadog::CI::TestSuite?
Running test suite that this test is part of (if any).
40 41 42 43 |
# File 'lib/datadog/ci/test.rb', line 40 def test_suite suite_name = test_suite_name CI.active_test_suite(suite_name) if suite_name end |
#test_suite_id ⇒ String
Span id of the running test suite this test belongs to.
47 48 49 |
# File 'lib/datadog/ci/test.rb', line 47 def test_suite_id get_tag(Ext::Test::TAG_TEST_SUITE_ID) end |