Commit 6364a1d9 authored by Shinya Maeda's avatar Shinya Maeda

Fix merge train unnecessarily retries pipeline by a race condition

This commit fixes the problem by evaluating in_progress_merge_sha.
parent c02b84e4
......@@ -79,6 +79,8 @@ module MergeRequests
end
merge_request.update!(merge_commit_sha: commit_id)
ensure
merge_request.update_column(:in_progress_merge_commit_sha, nil)
end
def try_merge
......@@ -89,8 +91,6 @@ module MergeRequests
rescue => e
handle_merge_error(log_message: e.message)
raise_error('Something went wrong during merge')
ensure
merge_request.update!(in_progress_merge_commit_sha: nil)
end
def after_merge
......
---
title: Fix merge train unnecessarily retries pipeline by a race condition
merge_request: 24566
author:
type: fixed
......@@ -95,8 +95,9 @@ class MergeTrain < ApplicationRecord
end
def sha_exists_in_history?(target_project_id, target_branch, newrev, limit: 20)
MergeRequest.exists?(id: complete_merge_trains(target_project_id, target_branch, limit: limit),
merge_commit_sha: newrev)
MergeRequest.where(id: complete_merge_trains(target_project_id, target_branch, limit: limit))
.where('merge_commit_sha = ? OR in_progress_merge_commit_sha = ?', newrev, newrev)
.exists?
end
def total_count_in_train(merge_request)
......
......@@ -263,7 +263,7 @@ describe MergeTrain do
let!(:merge_request_1) { create_merge_request_on_train(status: :merging) }
before do
merge_request_1.update_column(:merge_commit_sha, merge_commit_sha_1)
merge_request_1.update_column(:in_progress_merge_commit_sha, merge_commit_sha_1)
end
it { is_expected.to eq(true) }
......
......@@ -31,6 +31,11 @@ describe MergeRequests::MergeService do
it { expect(merge_request).to be_valid }
it { expect(merge_request).to be_merged }
it 'persists merge_commit_sha and nullifies in_progress_merge_commit_sha' do
expect(merge_request.merge_commit_sha).not_to be_nil
expect(merge_request.in_progress_merge_commit_sha).to be_nil
end
it 'sends email to user2 about merge of new merge_request' do
email = ActionMailer::Base.deliveries.last
expect(email.to.first).to eq(user2.email)
......
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