diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/support/helpers/exclusive_lease_helpers.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/support/helpers/exclusive_lease_helpers.rb')
-rw-r--r-- | spec/support/helpers/exclusive_lease_helpers.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/support/helpers/exclusive_lease_helpers.rb b/spec/support/helpers/exclusive_lease_helpers.rb index 95cfc56c273..06e5ae5427c 100644 --- a/spec/support/helpers/exclusive_lease_helpers.rb +++ b/spec/support/helpers/exclusive_lease_helpers.rb @@ -2,6 +2,8 @@ module ExclusiveLeaseHelpers def stub_exclusive_lease(key = nil, uuid = 'uuid', renew: false, timeout: nil) + prepare_exclusive_lease_stub + key ||= instance_of(String) timeout ||= instance_of(Integer) @@ -37,4 +39,21 @@ module ExclusiveLeaseHelpers .to receive(:cancel) .with(key, uuid) end + + private + + # This prepares the stub to be able to stub specific lease keys + # while allowing unstubbed lease keys to behave as original. + # + # allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original + # can only be called once to prevent resetting stubs when + # `stub_exclusive_lease` is called multiple times. + def prepare_exclusive_lease_stub + return if @exclusive_lease_allowed_to_call_original + + allow(Gitlab::ExclusiveLease) + .to receive(:new).and_call_original + + @exclusive_lease_allowed_to_call_original = true + end end |