Merge branch '39032-improve-merge-ongoing-check-consistency' into 'master'
Make "merge ongoing" check more consistent Closes #39032 See merge request gitlab-org/gitlab-ce!14825
This commit is contained in:
commit
c616200f82
5 changed files with 46 additions and 2 deletions
|
@ -396,7 +396,7 @@ class MergeRequest < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def merge_ongoing?
|
||||
!!merge_jid && !merged?
|
||||
!!merge_jid && !merged? && Gitlab::SidekiqStatus.running?(merge_jid)
|
||||
end
|
||||
|
||||
def closed_without_fork?
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Make "merge ongoing" check more consistent
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -51,6 +51,13 @@ module Gitlab
|
|||
self.num_running(job_ids).zero?
|
||||
end
|
||||
|
||||
# Returns true if the given job is running
|
||||
#
|
||||
# job_id - The Sidekiq job ID to check.
|
||||
def self.running?(job_id)
|
||||
num_running([job_id]) > 0
|
||||
end
|
||||
|
||||
# Returns the number of jobs that are running.
|
||||
#
|
||||
# job_ids - The Sidekiq job IDs to check.
|
||||
|
|
|
@ -39,6 +39,18 @@ describe Gitlab::SidekiqStatus do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.running?', :clean_gitlab_redis_shared_state do
|
||||
it 'returns true if job is running' do
|
||||
described_class.set('123')
|
||||
|
||||
expect(described_class.running?('123')).to be(true)
|
||||
end
|
||||
|
||||
it 'returns false if job is not found' do
|
||||
expect(described_class.running?('123')).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.num_running', :clean_gitlab_redis_shared_state do
|
||||
it 'returns 0 if all jobs have been completed' do
|
||||
expect(described_class.num_running(%w(123))).to eq(0)
|
||||
|
|
|
@ -1460,11 +1460,31 @@ describe MergeRequest do
|
|||
end
|
||||
|
||||
describe '#merge_ongoing?' do
|
||||
it 'returns true when merge_id is present and MR is not merged' do
|
||||
it 'returns true when merge_id, MR is not merged and it has no running job' do
|
||||
merge_request = build_stubbed(:merge_request, state: :open, merge_jid: 'foo')
|
||||
allow(Gitlab::SidekiqStatus).to receive(:running?).with('foo') { true }
|
||||
|
||||
expect(merge_request.merge_ongoing?).to be(true)
|
||||
end
|
||||
|
||||
it 'returns false when merge_jid is nil' do
|
||||
merge_request = build_stubbed(:merge_request, state: :open, merge_jid: nil)
|
||||
|
||||
expect(merge_request.merge_ongoing?).to be(false)
|
||||
end
|
||||
|
||||
it 'returns false if MR is merged' do
|
||||
merge_request = build_stubbed(:merge_request, state: :merged, merge_jid: 'foo')
|
||||
|
||||
expect(merge_request.merge_ongoing?).to be(false)
|
||||
end
|
||||
|
||||
it 'returns false if there is no merge job running' do
|
||||
merge_request = build_stubbed(:merge_request, state: :open, merge_jid: 'foo')
|
||||
allow(Gitlab::SidekiqStatus).to receive(:running?).with('foo') { false }
|
||||
|
||||
expect(merge_request.merge_ongoing?).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#closed_without_fork?" do
|
||||
|
|
Loading…
Reference in a new issue