From e8a361dd0098a4f7b82199fbdeb3726ea2920219 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 3 Dec 2024 16:28:11 +0100 Subject: [PATCH] introduce TestOptimisation::Component#skippable? method to encapsulate the logic to check if a test should be skipped in the current test run --- lib/datadog/ci/contrib/rspec/example_group.rb | 5 ++++- lib/datadog/ci/test.rb | 15 ++++++++------- lib/datadog/ci/test_optimisation/component.rb | 13 +++++++++---- sig/datadog/ci/test.rbs | 4 ++-- sig/datadog/ci/test_optimisation/component.rbs | 2 ++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/datadog/ci/contrib/rspec/example_group.rb b/lib/datadog/ci/contrib/rspec/example_group.rb index 48017bca..124d4427 100644 --- a/lib/datadog/ci/contrib/rspec/example_group.rb +++ b/lib/datadog/ci/contrib/rspec/example_group.rb @@ -30,7 +30,10 @@ def run(reporter = ::RSpec::Core::NullReporter) ) # try skipping the whole example group - metadata[:skip] = true + # all_skipped = descendant_filtered_examples.all? do |example| + # end + all_skipped = false + metadata[:skip] = true if all_skipped success = super return success unless test_suite diff --git a/lib/datadog/ci/test.rb b/lib/datadog/ci/test.rb index 00912e43..d5d47b81 100644 --- a/lib/datadog/ci/test.rb +++ b/lib/datadog/ci/test.rb @@ -17,6 +17,11 @@ def name get_tag(Ext::Test::TAG_NAME) end + # @return [String] the test id according to Datadog's test impact analysis. + def datadog_test_id + @datadog_test_id ||= Utils::TestRun.datadog_test_id(name, test_suite_name, parameters) + end + # Finishes the current test. # @return [void] def finish @@ -140,22 +145,18 @@ def parameters # @internal def any_retry_passed? - !!test_suite&.any_test_retry_passed?(test_id) + !!test_suite&.any_test_retry_passed?(datadog_test_id) end private - def test_id - @test_id ||= Utils::TestRun.datadog_test_id(name, test_suite_name, parameters) - end - def record_test_result(datadog_status) # if this test was already executed in this test suite, mark it as retried - if test_suite&.test_executed?(test_id) + if test_suite&.test_executed?(datadog_test_id) set_tag(Ext::Test::TAG_IS_RETRY, "true") end - test_suite&.record_test_result(test_id, datadog_status) + test_suite&.record_test_result(datadog_test_id, datadog_status) end end end diff --git a/lib/datadog/ci/test_optimisation/component.rb b/lib/datadog/ci/test_optimisation/component.rb index 562ca6c9..e13add52 100644 --- a/lib/datadog/ci/test_optimisation/component.rb +++ b/lib/datadog/ci/test_optimisation/component.rb @@ -144,11 +144,16 @@ def stop_coverage(test) event end + def skippable?(test) + return false if !enabled? || !skipping_tests? + + @skippable_tests.include?(test.datadog_test_id) + end + def mark_if_skippable(test) return if !enabled? || !skipping_tests? - datadog_test_id = Utils::TestRun.datadog_test_id(test.name, test.test_suite_name, test.parameters) - if @skippable_tests.include?(datadog_test_id) + if skippable?(test) if forked? Datadog.logger.warn { "Intelligent test runner is not supported for forking test runners yet" } return @@ -156,9 +161,9 @@ def mark_if_skippable(test) test.set_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR, "true") - Datadog.logger.debug { "Marked test as skippable: #{datadog_test_id}" } + Datadog.logger.debug { "Marked test as skippable: #{test.datadog_test_id}" } else - Datadog.logger.debug { "Test is not skippable: #{datadog_test_id}" } + Datadog.logger.debug { "Test is not skippable: #{test.datadog_test_id}" } end end diff --git a/sig/datadog/ci/test.rbs b/sig/datadog/ci/test.rbs index 0c2aaef6..63aaf06c 100644 --- a/sig/datadog/ci/test.rbs +++ b/sig/datadog/ci/test.rbs @@ -1,8 +1,9 @@ module Datadog module CI class Test < Span - @test_id: String + @datadog_test_id: String + def datadog_test_id: () -> String def finish: () -> void def test_suite: () -> Datadog::CI::TestSuite? def test_suite_id: () -> String? @@ -17,7 +18,6 @@ module Datadog private - def test_id: () -> String def record_test_result: (String datadog_status) -> void end end diff --git a/sig/datadog/ci/test_optimisation/component.rbs b/sig/datadog/ci/test_optimisation/component.rbs index afbd7bf8..0a745c61 100644 --- a/sig/datadog/ci/test_optimisation/component.rbs +++ b/sig/datadog/ci/test_optimisation/component.rbs @@ -45,6 +45,8 @@ module Datadog def stop_coverage: (Datadog::CI::Test test) -> Datadog::CI::TestOptimisation::Coverage::Event? + def skippable?: (Datadog::CI::Test test) -> bool + def mark_if_skippable: (Datadog::CI::Test test) -> void def count_skipped_test: (Datadog::CI::Test test) -> void