Module: Datadog::CI::Contrib::ParallelTests::CLI::InstanceMethods

Defined in:
lib/datadog/ci/contrib/parallel_tests/cli.rb

Instance Method Summary collapse

Instance Method Details

#any_test_failed?(test_results) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/datadog/ci/contrib/parallel_tests/cli.rb', line 49

def any_test_failed?(test_results)
  res = super

  test_session = test_tracing_component.active_test_session
  test_module = test_tracing_component.active_test_module
  if res
    test_module&.failed!
    test_session&.failed!
  else
    test_module&.passed!
    test_session&.passed!
  end

  res
end

#datadog_configuration ⇒ Object



79
80
81
# File 'lib/datadog/ci/contrib/parallel_tests/cli.rb', line 79

def datadog_configuration
  Datadog.configuration.ci[:paralleltests]
end

#datadog_extract_rspec_version ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/datadog/ci/contrib/parallel_tests/cli.rb', line 65

def datadog_extract_rspec_version
  # Try to find either 'rspec' or 'rspec-core' gem
  if Gem.loaded_specs["rspec"]
    Gem.loaded_specs["rspec"].version.to_s
  elsif Gem.loaded_specs["rspec-core"]
    Gem.loaded_specs["rspec-core"].version.to_s
  else
    "0.0.0"
  end
rescue => e
  Datadog.logger.debug("Error extracting RSpec version: #{e.class.name} - #{e.message}")
  "0.0.0"
end

#run_tests_in_parallel(num_processes, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog/ci/contrib/parallel_tests/cli.rb', line 17

def run_tests_in_parallel(num_processes, options)
  # only rspec runner is supported for now
  return super if @runner != ::ParallelTests::RSpec::Runner

  Utils::FileStorage.with_new_namespace do |storage_namespace|
    # Preserve activation explicitly for the RSpec worker commands.
    # Starting the distributed parent session removes inherited
    # activation before unrelated child processes can receive it.
    worker_rubyopt = ENV["RUBYOPT"]
    test_session = test_tracing_component.start_test_session(
      tags: {
        CI::Ext::Test::TAG_FRAMEWORK => CI::Contrib::RSpec::Ext::FRAMEWORK,
        CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_extract_rspec_version
      },
      service: datadog_configuration[:service_name],
      estimated_total_tests_count: 10_000, # temporary value, updated by child processes
      distributed: true
    )
    test_module = test_tracing_component.start_test_module("rspec")

    options[:env] ||= {}
    options[:env][CI::Ext::Settings::ENV_TEST_VISIBILITY_DRB_SERVER_URI] = test_tracing_component.context_service_uri
    options[:env][Utils::FileStorage::ENV_NAMESPACE] = storage_namespace
    options[:env]["RUBYOPT"] ||= worker_rubyopt if worker_rubyopt

    super
  ensure
    test_module&.finish
    test_session&.finish
  end
end

#test_tracing_component ⇒ Object



83
84
85
# File 'lib/datadog/ci/contrib/parallel_tests/cli.rb', line 83

def test_tracing_component
  Datadog.send(:components).test_tracing
end