Class: Datadog::CI::TestOptimisation::SkippablePercentage::Calculator
- Defined in:
- lib/datadog/ci/test_optimisation/skippable_percentage/calculator.rb
Overview
This class calculates the percentage of tests that are going to be skipped in the next run without actually running the tests.
It is useful to determine the number of parallel jobs that are required for the CI pipeline.
NOTE: Only RSpec is supported at the moment.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(rspec_cli_options: [], verbose: false, spec_path: "spec") ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize(rspec_cli_options: [], verbose: false, spec_path: "spec") ⇒ Calculator
Returns a new instance of Calculator.
16 17 18 19 20 |
# File 'lib/datadog/ci/test_optimisation/skippable_percentage/calculator.rb', line 16 def initialize(rspec_cli_options: [], verbose: false, spec_path: "spec") super(verbose: verbose, spec_path: spec_path) @rspec_cli_options = || [] end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/datadog/ci/test_optimisation/skippable_percentage/calculator.rb', line 22 def call return 0.0 if @failed require_rspec! return 0.0 if @failed configure_datadog exit_code = dry_run if exit_code != 0 Datadog.logger.error("RSpec dry-run failed with exit code #{exit_code}") @failed = true return 0.0 end log("Total tests count: #{test_optimisation.total_tests_count}") log("Skipped tests count: #{test_optimisation.skipped_tests_count}") validate_test_optimisation_state! (test_optimisation.skipped_tests_count.to_f / test_optimisation.total_tests_count.to_f).floor(2) end |