Skip to content

Commit

Permalink
request skippable tests when configuring ITR
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 12, 2024
1 parent 9641d3a commit e1493a5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
23 changes: 22 additions & 1 deletion lib/datadog/ci/itr/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative "../utils/parsing"

require_relative "coverage/event"
require_relative "skippable"

module Datadog
module CI
Expand All @@ -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(
Expand All @@ -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?
Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions sig/datadog/ci/itr/runner.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e1493a5

Please sign in to comment.