Class: Datadog::CI::TestDiscovery::Component

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(enabled:, output_path:) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
19
20
21
22
23
# File 'lib/datadog/ci/test_discovery/component.rb', line 14

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



25
26
27
# File 'lib/datadog/ci/test_discovery/component.rb', line 25

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/datadog/ci/test_discovery/component.rb', line 33

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/datadog/ci/test_discovery/component.rb', line 29

def enabled?
  @enabled
end

#finishObject



71
72
73
74
75
76
77
# File 'lib/datadog/ci/test_discovery/component.rb', line 71

def finish
  return unless @enabled

  @buffer_mutex.synchronize do
    flush_buffer_unsafe if @buffer.any?
  end
end

#record_test(name:, suite:, module_name:, parameters:, source_file:) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/datadog/ci/test_discovery/component.rb', line 79

def record_test(name:, suite:, module_name:, parameters:, source_file:)
  name = name.nil? ? nil : Utils::TestName.normalize(name)
  suite = suite.nil? ? nil : Utils::TestName.normalize(suite)

  test_info = {
    "name" => name,
    "suite" => suite,
    "module" => module_name,
    "parameters" => parameters,
    "suiteSourceFile" => source_file
  }

  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



100
101
102
103
104
105
106
# File 'lib/datadog/ci/test_discovery/component.rb', line 100

def shutdown!
  return unless @enabled

  @buffer_mutex.synchronize do
    flush_buffer_unsafe if @buffer.any?
  end
end

#startObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/datadog/ci/test_discovery/component.rb', line 52

def 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