Class: Datadog::CI::TestSuite
- Inherits:
-
ConcurrentSpan
- Object
- Span
- ConcurrentSpan
- Datadog::CI::TestSuite
- Defined in:
- lib/datadog/ci/test_suite.rb,
sig/datadog/ci/test_suite.rbs
Overview
Represents a single test suite.
Read here on what test suite means: https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#suite
This object can be shared between multiple threads.
Instance Attribute Summary
Attributes inherited from Span
Instance Method Summary collapse
- #all_executions_failed?(test_id) ⇒ Boolean
- #all_executions_passed?(test_id) ⇒ Boolean
- #any_passed? ⇒ Boolean
- #any_test_retry_passed?(test_id) ⇒ Boolean
- #expected_test_done!(test_name) ⇒ void
-
#finish ⇒ void
Finishes this test suite.
-
#initialize(tracer_span) ⇒ TestSuite
constructor
A new instance of TestSuite.
- #record_test_final_status(test_id, final_status) ⇒ void
- #record_test_result(test_id, datadog_test_status) ⇒ void
- #set_expected_tests!(expected_tests) ⇒ void
- #set_status_from_stats! ⇒ void
- #test_executed?(test_id) ⇒ Boolean
Methods inherited from ConcurrentSpan
#failed!, #get_tag, #passed!, #set_default_tags, #set_environment_runtime_tags, #set_metric, #set_tag, #set_tags, #skipped!, #synchronize
Methods inherited from Span
#base_commit_sha, #clear_tag, #failed!, #failed?, #get_metric, #get_tag, #git_branch, #git_commit_message, #git_commit_sha, #git_repository_url, #git_tag, #id, #name, #original_git_commit_message, #original_git_commit_sha, #os_architecture, #os_platform, #os_version, #passed!, #passed?, #runtime_name, #runtime_version, #service, #set_default_tags, #set_environment_runtime_tags, #set_metric, #set_parameters, #set_tag, #set_tags, #skipped!, #skipped?, #source_file, #status, #test_tracing, #to_s, #trace_id, #type, #undefined?
Constructor Details
#initialize(tracer_span) ⇒ TestSuite
Returns a new instance of TestSuite.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/datadog/ci/test_suite.rb', line 16 def initialize(tracer_span) super # counts how many times every test in this suite was executed with each status: # { "MySuite.mytest.a:1" => { "pass" => 3, "fail" => 2 } } @execution_stats_per_test = {} # tracks final status for each test (the status that is reported after all retries): # { "MySuite.mytest.a:1" => "pass" } @final_statuses_per_test = {} end |
Instance Method Details
#all_executions_failed?(test_id) ⇒ Boolean
74 75 76 77 78 79 |
# File 'lib/datadog/ci/test_suite.rb', line 74 def all_executions_failed?(test_id) synchronize do stats = @execution_stats_per_test[test_id] stats && stats[Ext::Test::Status::FAIL] > 0 && stats[Ext::Test::Status::PASS] == 0 end end |
#all_executions_passed?(test_id) ⇒ Boolean
82 83 84 85 86 87 |
# File 'lib/datadog/ci/test_suite.rb', line 82 def all_executions_passed?(test_id) synchronize do stats = @execution_stats_per_test[test_id] stats && stats[Ext::Test::Status::PASS] > 0 && stats[Ext::Test::Status::FAIL] == 0 end end |
#any_passed? ⇒ Boolean
57 58 59 60 61 62 63 |
# File 'lib/datadog/ci/test_suite.rb', line 57 def any_passed? synchronize do @execution_stats_per_test.any? do |_, stats| stats[Ext::Test::Status::PASS] > 0 end end end |
#any_test_retry_passed?(test_id) ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/datadog/ci/test_suite.rb', line 66 def any_test_retry_passed?(test_id) synchronize do stats = @execution_stats_per_test[test_id] stats && stats[Ext::Test::Status::PASS] > 0 end end |
#expected_test_done!(test_name) ⇒ void
This method returns an undefined value.
106 107 108 109 110 111 112 |
# File 'lib/datadog/ci/test_suite.rb', line 106 def expected_test_done!(test_name) synchronize do @expected_tests_set.delete(test_name) finish if @expected_tests_set.empty? end end |
#finish ⇒ void
This method returns an undefined value.
Finishes this test suite.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datadog/ci/test_suite.rb', line 30 def finish synchronize do # we try to derive test suite status from execution stats if no status was set explicitly set_status_from_stats! if undefined? test_tracing.deactivate_test_suite(name) super end end |
#record_test_final_status(test_id, final_status) ⇒ void
This method returns an undefined value.
50 51 52 53 54 |
# File 'lib/datadog/ci/test_suite.rb', line 50 def record_test_final_status(test_id, final_status) synchronize do @final_statuses_per_test[test_id] = final_status end end |
#record_test_result(test_id, datadog_test_status) ⇒ void
This method returns an undefined value.
42 43 44 45 46 47 |
# File 'lib/datadog/ci/test_suite.rb', line 42 def record_test_result(test_id, datadog_test_status) synchronize do @execution_stats_per_test[test_id] ||= Hash.new(0) @execution_stats_per_test[test_id][datadog_test_status] += 1 end end |
#set_expected_tests!(expected_tests) ⇒ void
This method returns an undefined value.
97 98 99 100 101 102 103 |
# File 'lib/datadog/ci/test_suite.rb', line 97 def set_expected_tests!(expected_tests) synchronize do return if @expected_tests_set @expected_tests_set = Set.new(expected_tests) end end |
#set_status_from_stats! ⇒ void
This method returns an undefined value.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/datadog/ci/test_suite.rb', line 116 def set_status_from_stats! synchronize do # count how many tests have each final status test_suite_stats = @final_statuses_per_test.each_with_object(Hash.new(0)) do |(_test_id, final_status), acc| acc[final_status] += 1 end # test suite is considered failed if at least one test failed if test_suite_stats[Ext::Test::Status::FAIL] > 0 failed! # if there are no failures and no passes, it is skipped elsif test_suite_stats[Ext::Test::Status::PASS] == 0 skipped! # otherwise we consider it passed else passed! end end end |
#test_executed?(test_id) ⇒ Boolean
90 91 92 93 94 |
# File 'lib/datadog/ci/test_suite.rb', line 90 def test_executed?(test_id) synchronize do @execution_stats_per_test.key?(test_id) end end |