Commit beeaf441 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '207536-retried-jobs-are-not-able-to-find-knapsack-report' into 'master'

Keep the needs association on the retried jobs

See merge request gitlab-org/gitlab!25888
parents 0520e068 d1ee168e
...@@ -90,6 +90,12 @@ module Ci ...@@ -90,6 +90,12 @@ module Ci
end end
end end
def needs_attributes
strong_memoize(:needs_attributes) do
needs.map { |need| need.attributes.except('id', 'build_id') }
end
end
private private
def validate_scheduling_type? def validate_scheduling_type?
......
...@@ -5,7 +5,8 @@ module Ci ...@@ -5,7 +5,8 @@ module Ci
CLONE_ACCESSORS = %i[pipeline project ref tag options name CLONE_ACCESSORS = %i[pipeline project ref tag options name
allow_failure stage stage_id stage_idx trigger_request allow_failure stage stage_id stage_idx trigger_request
yaml_variables when environment coverage_regex yaml_variables when environment coverage_regex
description tag_list protected needs resource_group scheduling_type].freeze description tag_list protected needs_attributes
resource_group scheduling_type].freeze
def execute(build) def execute(build)
reprocess!(build).tap do |new_build| reprocess!(build).tap do |new_build|
......
---
title: Keep needs association on the retried build
merge_request: 25888
author:
type: fixed
...@@ -145,4 +145,28 @@ describe Ci::Processable do ...@@ -145,4 +145,28 @@ describe Ci::Processable do
expect(another_build.reload.scheduling_type).to be_nil expect(another_build.reload.scheduling_type).to be_nil
end end
end end
describe '#needs_attributes' do
let(:build) { create(:ci_build, :created, project: project, pipeline: pipeline) }
context 'with needs' do
before do
create(:ci_build_need, build: build, name: 'test1')
create(:ci_build_need, build: build, name: 'test2')
end
it 'returns all needs attributes' do
expect(build.needs_attributes).to contain_exactly(
{ 'artifacts' => true, 'name' => 'test1' },
{ 'artifacts' => true, 'name' => 'test2' }
)
end
end
context 'without needs' do
it 'returns all needs attributes' do
expect(build.needs_attributes).to be_empty
end
end
end
end end
...@@ -36,7 +36,7 @@ describe Ci::RetryBuildService do ...@@ -36,7 +36,7 @@ describe Ci::RetryBuildService do
job_artifacts_performance job_artifacts_lsif job_artifacts_performance job_artifacts_lsif
job_artifacts_codequality job_artifacts_metrics scheduled_at job_artifacts_codequality job_artifacts_metrics scheduled_at
job_variables waiting_for_resource_at job_artifacts_metrics_referee job_variables waiting_for_resource_at job_artifacts_metrics_referee
job_artifacts_network_referee].freeze job_artifacts_network_referee needs].freeze
IGNORE_ACCESSORS = IGNORE_ACCESSORS =
%i[type lock_version target_url base_tags trace_sections %i[type lock_version target_url base_tags trace_sections
...@@ -46,7 +46,8 @@ describe Ci::RetryBuildService do ...@@ -46,7 +46,8 @@ describe Ci::RetryBuildService do
sourced_pipelines artifacts_file_store artifacts_metadata_store sourced_pipelines artifacts_file_store artifacts_metadata_store
metadata runner_session trace_chunks upstream_pipeline_id metadata runner_session trace_chunks upstream_pipeline_id
artifacts_file artifacts_metadata artifacts_size commands artifacts_file artifacts_metadata artifacts_size commands
resource resource_group_id processed security_scans].freeze resource resource_group_id processed security_scans author
pipeline_id].freeze
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) } let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
...@@ -79,8 +80,15 @@ describe Ci::RetryBuildService do ...@@ -79,8 +80,15 @@ describe Ci::RetryBuildService do
end end
describe 'clone accessors' do describe 'clone accessors' do
let(:forbidden_associations) do
Ci::Build.reflect_on_all_associations.each_with_object(Set.new) do |assoc, memo|
memo << assoc.name unless assoc.macro == :belongs_to
end
end
CLONE_ACCESSORS.each do |attribute| CLONE_ACCESSORS.each do |attribute|
it "clones #{attribute} build attribute" do it "clones #{attribute} build attribute" do
expect(attribute).not_to be_in(forbidden_associations), "association #{attribute} must be `belongs_to`"
expect(build.send(attribute)).not_to be_nil expect(build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).not_to be_nil expect(new_build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).to eq build.send(attribute) expect(new_build.send(attribute)).to eq build.send(attribute)
...@@ -97,9 +105,17 @@ describe Ci::RetryBuildService do ...@@ -97,9 +105,17 @@ describe Ci::RetryBuildService do
expect(new_build.protected).to eq build.protected expect(new_build.protected).to eq build.protected
end end
end end
it 'clones only the needs attributes' do
expect(new_build.needs.exists?).to be_truthy
expect(build.needs.exists?).to be_truthy
expect(new_build.needs_attributes).to match(build.needs_attributes)
expect(new_build.needs).not_to match(build.needs)
end
end end
describe 'reject acessors' do describe 'reject accessors' do
REJECT_ACCESSORS.each do |attribute| REJECT_ACCESSORS.each do |attribute|
it "does not clone #{attribute} build attribute" do it "does not clone #{attribute} build attribute" do
expect(new_build.send(attribute)).not_to eq build.send(attribute) expect(new_build.send(attribute)).not_to eq build.send(attribute)
...@@ -117,8 +133,9 @@ describe Ci::RetryBuildService do ...@@ -117,8 +133,9 @@ describe Ci::RetryBuildService do
# #
current_accessors = current_accessors =
Ci::Build.attribute_names.map(&:to_sym) + Ci::Build.attribute_names.map(&:to_sym) +
Ci::Build.attribute_aliases.keys.map(&:to_sym) +
Ci::Build.reflect_on_all_associations.map(&:name) + Ci::Build.reflect_on_all_associations.map(&:name) +
[:tag_list] [:tag_list, :needs_attributes]
current_accessors.uniq! current_accessors.uniq!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment