Class: Datadog::CI::TestManagement::Component
- Inherits:
-
Object
- Object
- Datadog::CI::TestManagement::Component
- Includes:
- Utils::Stateful
- Defined in:
- lib/datadog/ci/test_management/component.rb
Overview
Test management is a feature that lets people manage their flaky tests in Datadog. It includes:
-
marking test as quarantined causes test to continue running but not failing the build
-
marking test as disabled causes test to be skipped
-
marking test as “attempted to fix” causes test to be retried many times to confirm that fix worked
Constant Summary collapse
- FILE_STORAGE_KEY =
"test_management_component_state"
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#tests_properties ⇒ Object
readonly
Returns the value of attribute tests_properties.
Instance Method Summary collapse
- #attempt_to_fix?(datadog_fqn_test_id) ⇒ Boolean
- #configure(library_settings, test_session) ⇒ Object
-
#initialize(enabled:, tests_properties_client:) ⇒ Component
constructor
A new instance of Component.
- #restore_state(state) ⇒ Object
-
#serialize_state ⇒ Object
Implementation of Stateful interface.
- #storage_key ⇒ Object
- #tag_test_from_properties(test_span) ⇒ Object
Methods included from Utils::Stateful
#load_component_state, #store_component_state
Constructor Details
#initialize(enabled:, tests_properties_client:) ⇒ Component
Returns a new instance of Component.
24 25 26 27 28 29 |
# File 'lib/datadog/ci/test_management/component.rb', line 24 def initialize(enabled:, tests_properties_client:) @enabled = enabled @tests_properties_client = tests_properties_client @tests_properties = {} end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
22 23 24 |
# File 'lib/datadog/ci/test_management/component.rb', line 22 def enabled @enabled end |
#tests_properties ⇒ Object (readonly)
Returns the value of attribute tests_properties.
22 23 24 |
# File 'lib/datadog/ci/test_management/component.rb', line 22 def tests_properties @tests_properties end |
Instance Method Details
#attempt_to_fix?(datadog_fqn_test_id) ⇒ Boolean
68 69 70 71 72 73 74 75 |
# File 'lib/datadog/ci/test_management/component.rb', line 68 def attempt_to_fix?(datadog_fqn_test_id) return false unless @enabled test_properties = @tests_properties[datadog_fqn_test_id] return false if test_properties.nil? test_properties.fetch("attempt_to_fix", false) end |
#configure(library_settings, test_session) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datadog/ci/test_management/component.rb', line 31 def configure(library_settings, test_session) @enabled &&= library_settings.test_management_enabled? return unless @enabled test_session.set_tag(Ext::Test::TAG_TEST_MANAGEMENT_ENABLED, "true") # Load component state first, and if successful, skip fetching tests properties if !load_component_state @tests_properties = @tests_properties_client.fetch(test_session) store_component_state if test_session.distributed end Utils::Telemetry.distribution( Ext::Telemetry::METRIC_TEST_MANAGEMENT_TESTS_RESPONSE_TESTS, @tests_properties.count.to_f ) end |
#restore_state(state) ⇒ Object
84 85 86 |
# File 'lib/datadog/ci/test_management/component.rb', line 84 def restore_state(state) @tests_properties = state[:tests_properties] end |
#serialize_state ⇒ Object
Implementation of Stateful interface
78 79 80 81 82 |
# File 'lib/datadog/ci/test_management/component.rb', line 78 def serialize_state { tests_properties: @tests_properties } end |
#storage_key ⇒ Object
88 89 90 |
# File 'lib/datadog/ci/test_management/component.rb', line 88 def storage_key FILE_STORAGE_KEY end |
#tag_test_from_properties(test_span) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/datadog/ci/test_management/component.rb', line 50 def tag_test_from_properties(test_span) return unless @enabled datadog_test_id = Utils::TestRun.datadog_test_id(test_span.name, test_span.test_suite_name) test_properties = @tests_properties[datadog_test_id] if test_properties.nil? Datadog.logger.debug { "Test properties not found for test: #{datadog_test_id}" } return end Datadog.logger.debug { "Test properties for test #{datadog_test_id} are: [#{test_properties}]" } test_span.set_tag(Ext::Test::TAG_IS_QUARANTINED, "true") if test_properties["quarantined"] test_span.set_tag(Ext::Test::TAG_IS_TEST_DISABLED, "true") if test_properties["disabled"] test_span.set_tag(Ext::Test::TAG_IS_ATTEMPT_TO_FIX, "true") if test_properties["attempt_to_fix"] end |