Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIVIS-2934] Request skippable tests when configuring ITR #159

Merged
merged 10 commits into from
Apr 17, 2024
Next Next commit
request skippable tests when configuring ITR
anmarchenko committed Apr 12, 2024
commit e1493a5eb6986ef0a1d50d93aada64902ce80c85
1 change: 1 addition & 0 deletions lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ def activate_ci!(settings)
)

itr = ITR::Runner.new(
api: test_visibility_api,
coverage_writer: coverage_writer,
enabled: settings.ci.enabled && settings.ci.itr_enabled
)
23 changes: 22 additions & 1 deletion lib/datadog/ci/itr/runner.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
require_relative "../utils/parsing"

require_relative "coverage/event"
require_relative "skippable"

module Datadog
module CI
@@ -18,20 +19,28 @@ module ITR
# Integrates with backend to provide test impact analysis data and
# skip tests that are not impacted by the changes
class Runner
attr_reader :correlation_id, :skippable_tests

def initialize(
api: nil,
coverage_writer: nil,
enabled: false
)
@enabled = enabled
@api = api

@test_skipping_enabled = false
@code_coverage_enabled = false

@coverage_writer = coverage_writer

@correlation_id = nil
@skippable_tests = []

Datadog.logger.debug("ITR Runner initialized with enabled: #{@enabled}")
end

def configure(remote_configuration, test_session)
def configure(remote_configuration, test_session:, git_tree_upload_worker:)
Datadog.logger.debug("Configuring ITR Runner with remote configuration: #{remote_configuration}")

@enabled = Utils::Parsing.convert_to_bool(
@@ -55,6 +64,18 @@ def configure(remote_configuration, test_session)
load_datadog_cov! if @code_coverage_enabled

Datadog.logger.debug("Configured ITR Runner with enabled: #{@enabled}, skipping_tests: #{@test_skipping_enabled}, code_coverage: #{@code_coverage_enabled}")

return unless skipping_tests?

# we can only request skippable tests if git metadata is already uploaded
git_tree_upload_worker.wait_until_done

skippable_response = Skippable.new(api: @api).fetch_skippable_tests(test_session)
@correlation_id = skippable_response.correlation_id
@skippable_tests = skippable_response.tests

Datadog.logger.debug { "Fetched skippable tests: \n #{@skippable_tests}" }
Datadog.logger.debug { "ITR correlation ID: #{@correlation_id}" }
end

def enabled?
7 changes: 6 additions & 1 deletion lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
@@ -229,7 +229,12 @@ def configure_library(test_session)
Datadog.logger.debug { "git metadata upload did not complete in time when configuring library" }
end
end
@itr.configure(remote_configuration.payload, test_session)

@itr.configure(
remote_configuration.payload,
test_session: test_session,
git_tree_upload_worker: @git_tree_upload_worker
)
end

def skip_tracing(block = nil)
9 changes: 6 additions & 3 deletions sig/datadog/ci/itr/runner.rbs
Original file line number Diff line number Diff line change
@@ -5,12 +5,15 @@ module Datadog
@enabled: bool
@test_skipping_enabled: bool
@code_coverage_enabled: bool
@api: Datadog::CI::Transport::Api::Base?
@correlation_id: String
@skippable_tests: Array[Datadog::CI::ITR::Skippable::Test]
@coverage_writer: Datadog::CI::ITR::Coverage::Writer?

def initialize: (?enabled: bool, coverage_writer: Datadog::CI::ITR::Coverage::Writer?) -> void
@api: Datadog::CI::Transport::Api::Base?

def initialize: (?enabled: bool, coverage_writer: Datadog::CI::ITR::Coverage::Writer?, api: Datadog::CI::Transport::Api::Base?) -> void

def configure: (Hash[String, untyped] remote_configuration, Datadog::CI::TestSession test_session) -> void
def configure: (Hash[String, untyped] remote_configuration, test_session: Datadog::CI::TestSession, git_tree_upload_worker: Datadog::CI::Worker) -> void

def enabled?: () -> bool