diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 08:17:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 08:17:02 +0000 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/lib/gitlab/exclusive_lease_helpers | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) | |
download | gitlab-ce-b39512ed755239198a9c294b6a45e65c05900235.tar.gz |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/exclusive_lease_helpers')
-rw-r--r-- | spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb b/spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb index f74fbf1206f..1f30ac79488 100644 --- a/spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb +++ b/spec/lib/gitlab/exclusive_lease_helpers/sleeping_lock_spec.rb @@ -52,6 +52,28 @@ RSpec.describe Gitlab::ExclusiveLeaseHelpers::SleepingLock, :clean_gitlab_redis_ end end + context 'when the lease is obtained already' do + let!(:lease) { stub_exclusive_lease_taken(key) } + + context 'when retries are not specified' do + it 'retries to obtain a lease and raises an error' do + expect(lease).to receive(:try_obtain).exactly(10).times + + expect { subject.obtain }.to raise_error('Failed to obtain a lock') + end + end + + context 'when specified retries are above the maximum attempts' do + let(:max_attempts) { 100 } + + it 'retries to obtain a lease and raises an error' do + expect(lease).to receive(:try_obtain).exactly(65).times + + expect { subject.obtain(max_attempts) }.to raise_error('Failed to obtain a lock') + end + end + end + context 'when the lease is held elsewhere' do let!(:lease) { stub_exclusive_lease_taken(key) } let(:max_attempts) { 7 } |