Commit 9ab02540 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Make "merge ongoing" check more consistent

parent efeaf3bd
...@@ -396,7 +396,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -396,7 +396,7 @@ class MergeRequest < ActiveRecord::Base
end end
def merge_ongoing? def merge_ongoing?
!!merge_jid && !merged? !!merge_jid && !merged? && Gitlab::SidekiqStatus.num_running([merge_jid]) > 0
end end
def closed_without_fork? def closed_without_fork?
......
---
title: Make "merge ongoing" check more consistent
merge_request:
author:
type: fixed
...@@ -1460,11 +1460,31 @@ describe MergeRequest do ...@@ -1460,11 +1460,31 @@ describe MergeRequest do
end end
describe '#merge_ongoing?' do 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') merge_request = build_stubbed(:merge_request, state: :open, merge_jid: 'foo')
allow(Gitlab::SidekiqStatus).to receive(:num_running).with(['foo']) { 1 }
expect(merge_request.merge_ongoing?).to be(true) expect(merge_request.merge_ongoing?).to be(true)
end 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(:num_running).with(['foo']) { 0 }
expect(merge_request.merge_ongoing?).to be(false)
end
end end
describe "#closed_without_fork?" do describe "#closed_without_fork?" do
......
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