debian-mirror-gitlab/spec/lib/gitlab/reference_counter_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.7 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::ReferenceCounter, :clean_gitlab_redis_shared_state do
2018-03-17 18:26:18 +05:30
let(:reference_counter) { described_class.new('project-1') }
2020-04-08 14:13:33 +05:30
describe '#increase' do
it 'increases and sets the expire time of a reference count for a path' do
expect { reference_counter.increase }.to change { reference_counter.value }.by(1)
expect(reference_counter.expires_in).to be_positive
expect(reference_counter.increase).to be(true)
end
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
describe '#decrease' do
it 'decreases the reference count for a path' do
reference_counter.increase
expect { reference_counter.decrease }.to change { reference_counter.value }.by(-1)
end
it 'warns if attempting to decrease a counter with a value of zero or less, and resets the counter' do
2020-11-24 15:15:51 +05:30
expect(Gitlab::AppLogger).to receive(:warn).with("Reference counter for project-1" \
2020-04-08 14:13:33 +05:30
" decreased when its value was less than 1. Resetting the counter.")
expect { reference_counter.decrease }.not_to change { reference_counter.value }
end
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
describe '#value' do
it 'get the reference count for a path' do
expect(reference_counter.value).to eq(0)
reference_counter.increase
expect(reference_counter.value).to eq(1)
end
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
describe '#reset!' do
it 'resets reference count down to zero' do
3.times { reference_counter.increase }
expect { reference_counter.reset! }.to change { reference_counter.value}.from(3).to(0)
end
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
describe '#expires_in' do
it 'displays the expiration time in seconds' do
reference_counter.increase
expect(reference_counter.expires_in).to be_between(500, 600)
end
2018-03-17 18:26:18 +05:30
end
end