diff --git a/lib/datadog/ci/utils/test_run.rb b/lib/datadog/ci/utils/test_run.rb index 12ae1a5a..bfe4e500 100644 --- a/lib/datadog/ci/utils/test_run.rb +++ b/lib/datadog/ci/utils/test_run.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "etc" + module Datadog module CI module Utils @@ -34,6 +36,12 @@ def self.custom_configuration(env_tags) end res end + + def self.virtual_cpu_count + return @virtual_cpu_count if defined?(@virtual_cpu_count) + + @virtual_cpu_count = ::Etc.nprocessors + end end end end diff --git a/sig/datadog/ci/utils/test_run.rbs b/sig/datadog/ci/utils/test_run.rbs index 04240393..ae6aa36d 100644 --- a/sig/datadog/ci/utils/test_run.rbs +++ b/sig/datadog/ci/utils/test_run.rbs @@ -3,6 +3,7 @@ module Datadog module Utils module TestRun self.@command: String + self.@virtual_cpu_count: Integer def self.command: () -> String @@ -11,7 +12,13 @@ module Datadog def self.test_parameters: (?arguments: Hash[untyped, untyped], ?metadata: Hash[untyped, untyped]) -> String def self.custom_configuration: (Hash[String, String]? env_tags) -> Hash[String, String] + + def self.virtual_cpu_count: () -> Integer end end end end + +module Etc + def self.nprocessors: () -> Integer +end diff --git a/spec/datadog/ci/utils/test_run_spec.rb b/spec/datadog/ci/utils/test_run_spec.rb index d5b341dd..c0f1ce61 100644 --- a/spec/datadog/ci/utils/test_run_spec.rb +++ b/spec/datadog/ci/utils/test_run_spec.rb @@ -58,4 +58,10 @@ it { is_expected.to eq({"tag1" => "value1", "tag2" => "value2"}) } end end + + describe ".virtual_cpu_count" do + subject { described_class.virtual_cpu_count } + + it { is_expected.to eq(::Etc.nprocessors) } + end end