diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-08-01 14:58:14 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-08-01 14:58:14 +0000 |
commit | c017dc578dc78729050792d22b449ce0529479cf (patch) | |
tree | 4ed307f81cf1f6468413e31b22e04f6388f7301f /spec/lib/gitlab | |
parent | 354cd090521984dc95ce2ee2713b81a82aec2577 (diff) | |
parent | f4cd926cf3eec069396ab995b3553f40617c19e6 (diff) | |
download | gitlab-ce-c017dc578dc78729050792d22b449ce0529479cf.tar.gz |
Merge branch 'osw-avoid-errors-due-to-concurrent-calls' into 'master'
Add exclusive lease to mergeability check process
See merge request gitlab-org/gitlab-ce!31082
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/exclusive_lease_helpers_spec.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/spec/lib/gitlab/exclusive_lease_helpers_spec.rb b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb index 5107e1efbbd..c3b706fc538 100644 --- a/spec/lib/gitlab/exclusive_lease_helpers_spec.rb +++ b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb @@ -25,13 +25,13 @@ describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do end it 'calls the given block' do - expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_with_args(false) end it 'calls the given block continuously' do - expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once - expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once - expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_with_args(false) + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_with_args(false) + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_with_args(false) end it 'cancels the exclusive lease after the block' do @@ -68,6 +68,15 @@ describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do expect { subject }.to raise_error('Failed to obtain a lock') end + + context 'when lease is granted after retry' do + it 'yields block with true' do + expect(lease).to receive(:try_obtain).exactly(3).times { nil } + expect(lease).to receive(:try_obtain).once { unique_key } + + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_with_args(true) + end + end end context 'when sleep second is specified' do |