diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2016-10-27 14:59:52 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2016-11-04 14:30:11 +0100 |
commit | 6bcc52a53678ca68001189c801497862d3f6e758 (patch) | |
tree | 5b8ebf525e2fcf18d1e3c3b9de6c1e1d6180a94d /spec/lib/gitlab/exclusive_lease_spec.rb | |
parent | e4c05de75ccec1b0d64a7a994f05d54bffc903e5 (diff) | |
download | gitlab-ce-6bcc52a53678ca68001189c801497862d3f6e758.tar.gz |
Refine Git garbage collection
Diffstat (limited to 'spec/lib/gitlab/exclusive_lease_spec.rb')
-rw-r--r-- | spec/lib/gitlab/exclusive_lease_spec.rb | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/spec/lib/gitlab/exclusive_lease_spec.rb b/spec/lib/gitlab/exclusive_lease_spec.rb index 6b3bd08b978..a366d68a146 100644 --- a/spec/lib/gitlab/exclusive_lease_spec.rb +++ b/spec/lib/gitlab/exclusive_lease_spec.rb @@ -5,32 +5,47 @@ describe Gitlab::ExclusiveLease, type: :redis do describe '#try_obtain' do it 'cannot obtain twice before the lease has expired' do - lease = Gitlab::ExclusiveLease.new(unique_key, timeout: 3600) - expect(lease.try_obtain).to eq(true) + lease = described_class.new(unique_key, timeout: 3600) + expect(lease.try_obtain).to be_present expect(lease.try_obtain).to eq(false) end it 'can obtain after the lease has expired' do timeout = 1 - lease = Gitlab::ExclusiveLease.new(unique_key, timeout: timeout) + lease = described_class.new(unique_key, timeout: timeout) lease.try_obtain # start the lease sleep(2 * timeout) # lease should have expired now - expect(lease.try_obtain).to eq(true) + expect(lease.try_obtain).to be_present end end describe '#exists?' do it 'returns true for an existing lease' do - lease = Gitlab::ExclusiveLease.new(unique_key, timeout: 3600) + lease = described_class.new(unique_key, timeout: 3600) lease.try_obtain expect(lease.exists?).to eq(true) end it 'returns false for a lease that does not exist' do - lease = Gitlab::ExclusiveLease.new(unique_key, timeout: 3600) + lease = described_class.new(unique_key, timeout: 3600) expect(lease.exists?).to eq(false) end end + + describe '.cancel' do + it 'can cancel a lease' do + uuid = new_lease(unique_key) + expect(uuid).to be_present + expect(new_lease(unique_key)).to eq(false) + + described_class.cancel(unique_key, uuid) + expect(new_lease(unique_key)).to be_present + end + + def new_lease(key) + described_class.new(key, timeout: 3600).try_obtain + end + end end |