Commit 8824bc64 authored by Stan Hu's avatar Stan Hu

Merge branch 'create-persistent-ref-outside-of-transaction' into 'master'

Move persistent_ref.create into run_after_commit

Closes #36154

See merge request gitlab-org/gitlab!20422
parents 7617d2a4 dd388b3f
...@@ -247,10 +247,11 @@ module Ci ...@@ -247,10 +247,11 @@ module Ci
end end
after_transition pending: :running do |build| after_transition pending: :running do |build|
build.pipeline.persistent_ref.create
build.deployment&.run build.deployment&.run
build.run_after_commit do build.run_after_commit do
build.pipeline.persistent_ref.create
BuildHooksWorker.perform_async(id) BuildHooksWorker.perform_async(id)
end end
end end
......
---
title: Move persistent_ref.create into run_after_commit
merge_request: 20422
author:
type: fixed
...@@ -3086,12 +3086,22 @@ describe Ci::Build do ...@@ -3086,12 +3086,22 @@ describe Ci::Build do
rescue StateMachines::InvalidTransition rescue StateMachines::InvalidTransition
end end
it 'ensures pipeline ref existence' do context 'for pipeline ref existence' do
it 'ensures pipeline ref creation' do
expect(job.pipeline.persistent_ref).to receive(:create).once expect(job.pipeline.persistent_ref).to receive(:create).once
run_job_without_exception run_job_without_exception
end end
it 'ensures that it is not run in database transaction' do
expect(job.pipeline.persistent_ref).to receive(:create) do
expect(Gitlab::Database).not_to be_inside_transaction
end
run_job_without_exception
end
end
shared_examples 'saves data on transition' do shared_examples 'saves data on transition' do
it 'saves timeout' do it 'saves timeout' do
expect { job.run! }.to change { job.reload.ensure_metadata.timeout }.from(nil).to(expected_timeout) expect { job.run! }.to change { job.reload.ensure_metadata.timeout }.from(nil).to(expected_timeout)
......
...@@ -513,6 +513,16 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -513,6 +513,16 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect(json_response['features']).to eq(expected_features) expect(json_response['features']).to eq(expected_features)
end end
it 'creates persistent ref' do
expect_any_instance_of(Ci::PersistentRef).to receive(:create_ref)
.with(job.sha, "refs/#{Repository::REF_PIPELINES}/#{job.commit_id}")
request_job info: { platform: :darwin }
expect(response).to have_gitlab_http_status(201)
expect(json_response['id']).to eq(job.id)
end
context 'when job is made for tag' do context 'when job is made for tag' do
let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
......
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