Class: Datadog::CI::TestDiscovery::Component
- Inherits:
-
Object
- Object
- Datadog::CI::TestDiscovery::Component
- Defined in:
- lib/datadog/ci/test_discovery/component.rb
Overview
Test discovery mode component that manages test discovery output and lifecycle
Instance Method Summary collapse
- #configure(library_settings, test_session) ⇒ Object
- #disable_features_for_test_discovery!(settings) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(enabled:, output_path:) ⇒ Component
constructor
A new instance of Component.
- #on_test_session_end ⇒ Object
- #on_test_session_start ⇒ Object
- #on_test_started(test) ⇒ Object
- #shutdown! ⇒ Object
Constructor Details
#initialize(enabled:, output_path:) ⇒ Component
Returns a new instance of Component.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 13 def initialize( enabled:, output_path: ) @enabled = enabled @output_path = output_path @buffer = [] @buffer_mutex = Mutex.new end |
Instance Method Details
#configure(library_settings, test_session) ⇒ Object
24 25 26 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 24 def configure(library_settings, test_session) # This method is noop for this component, it is present for compatibility with other components end |
#disable_features_for_test_discovery!(settings) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 32 def disable_features_for_test_discovery!(settings) return unless @enabled Datadog.logger.debug("ATTENTION! Running in test discovery mode, disabling all features") # in test discovery mode don't send anything to Datadog settings.ci.discard_traces = true # Disable all feature flags when in test discovery mode settings.telemetry.enabled = false settings.ci.itr_enabled = false settings.ci. = false settings.ci.retry_failed_tests_enabled = false settings.ci.retry_new_tests_enabled = false settings.ci.test_management_enabled = false settings.ci.agentless_logs_submission_enabled = false settings.ci.impacted_tests_detection_enabled = false end |
#enabled? ⇒ Boolean
28 29 30 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 28 def enabled? @enabled end |
#on_test_session_end ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 70 def on_test_session_end return unless @enabled @buffer_mutex.synchronize do flush_buffer_unsafe if @buffer.any? end end |
#on_test_session_start ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 51 def on_test_session_start return unless @enabled if @output_path.nil? || @output_path&.empty? @output_path = Ext::TestDiscovery::DEFAULT_OUTPUT_PATH end # thanks RBS for this weirdness output_path = @output_path return unless output_path output_dir = File.dirname(output_path) FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir) Datadog.logger.debug { "Test discovery output path: #{output_path}" } @buffer_mutex.synchronize { @buffer.clear } end |
#on_test_started(test) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 78 def on_test_started(test) return unless @enabled # Mark test as being in test discovery mode so it will be skipped # even if we are not running in dry run mode. test.mark_test_discovery_mode! test_info = { "name" => test.name, "suite" => test.test_suite_name, "sourceFile" => test.source_file, "fqn" => test.datadog_test_id } Datadog.logger.debug { "Discovered test: #{test_info}" } @buffer_mutex.synchronize do @buffer << test_info flush_buffer_unsafe if @buffer.size >= Ext::TestDiscovery::MAX_BUFFER_SIZE end end |
#shutdown! ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/datadog/ci/test_discovery/component.rb', line 101 def shutdown! return unless @enabled @buffer_mutex.synchronize do flush_buffer_unsafe if @buffer.any? end end |