Skip to content

Commit

Permalink
introduce TestOptimisation::Component#skippable? method to encapsulat…
Browse files Browse the repository at this point in the history
…e the logic to check if a test should be skipped in the current test run
  • Loading branch information
anmarchenko committed Dec 3, 2024
1 parent e80271e commit e8a361d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lib/datadog/ci/contrib/rspec/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions lib/datadog/ci/test_optimisation/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,26 @@ 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
end

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

Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/ci/test.rbs
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -17,7 +18,6 @@ module Datadog

private

def test_id: () -> String
def record_test_result: (String datadog_status) -> void
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/test_optimisation/component.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8a361d

Please sign in to comment.