Skip to content

Commit

Permalink
wait for git upload and request library configuration again if requir…
Browse files Browse the repository at this point in the history
…e_git is true in library settings payload
  • Loading branch information
anmarchenko committed Apr 11, 2024
1 parent 77c51fb commit c564bbf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
9 changes: 9 additions & 0 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ def configure_library(test_session)
return unless itr_enabled?

remote_configuration = @remote_settings_api.fetch_library_settings(test_session)
# sometimes we can skip code coverage for default branch if there are no changes in the repository
# backend needs git metadata uploaded for this test session to check if we can skip code coverage
if remote_configuration.require_git?
Datadog.logger.debug { "Library configuration endpoint requires git upload to be finished, waiting..." }
@git_tree_upload_worker.wait_until_done

Datadog.logger.debug { "Requesting library configuration again..." }
remote_configuration = @remote_settings_api.fetch_library_settings(test_session)
end
@itr.configure(remote_configuration.payload, test_session)
end

Expand Down
61 changes: 32 additions & 29 deletions spec/datadog/ci/test_visibility/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -733,41 +733,44 @@
end

context "with ITR" do
include_context "CI mode activated" do
let(:itr_enabled) { true }
end
context "without require_git in settings response" do
include_context "CI mode activated" do
let(:itr_enabled) { true }
let(:tests_skipping_enabled) { true }
let(:code_coverage_enabled) { true }
end

describe "#start_test_session" do
let(:service) { "my-service" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }

subject { recorder.start_test_session(service: service, tags: tags) }

before do
settings_http_response = double(
"http-response",
ok?: true,
payload: {
"data" => {
"attributes" => {
"itr_enabled" => true,
"tests_skipping" => true,
"code_coverage" => true
}
}
}.to_json
)
allow_any_instance_of(Datadog::CI::Transport::RemoteSettingsApi).to receive(:fetch_library_settings).and_return(
Datadog::CI::Transport::RemoteSettingsApi::Response.new(settings_http_response)
)
it "returns a new CI test_session span with ITR tags" do
expect(subject).to be_kind_of(Datadog::CI::TestSession)
expect(subject.service).to eq(service)

expect(subject.skipping_tests?).to be true
expect(subject.code_coverage?).to be true
end
end
end

describe "#start_test_session" do
let(:service) { "my-service" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }
context "with require_git in settings response" do
include_context "CI mode activated" do
let(:itr_enabled) { true }
let(:tests_skipping_enabled) { true }
let(:code_coverage_enabled) { true }
let(:require_git) { true }
end

subject { recorder.start_test_session(service: service, tags: tags) }
describe "#start_test_session" do
let(:service) { "my-service" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }

it "returns a new CI test_session span with ITR tags" do
expect(subject).to be_kind_of(Datadog::CI::TestSession)
expect(subject.service).to eq(service)
subject { recorder.start_test_session(service: service, tags: tags) }

expect(subject.skipping_tests?).to be true
expect(subject.code_coverage?).to be true
it { is_expected.not_to be_skipping_tests }
end
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/support/contexts/ci_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let(:code_coverage_enabled) { false }
let(:tests_skipping_enabled) { false }
let(:git_metadata_upload_enabled) { false }
let(:require_git) { false }

let(:recorder) { Datadog.send(:components).ci_recorder }

Expand All @@ -40,7 +41,18 @@
"itr_enabled" => itr_enabled,
"code_coverage" => code_coverage_enabled,
"tests_skipping" => tests_skipping_enabled
}
},
require_git?: require_git
),
# This is for the second call to fetch_library_settings
double(
"remote_settings_api_response",
payload: {
"itr_enabled" => itr_enabled,
"code_coverage" => !code_coverage_enabled,
"tests_skipping" => !tests_skipping_enabled
},
require_git?: !require_git
)
)

Expand Down

0 comments on commit c564bbf

Please sign in to comment.