Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reference_counter_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83e4006c69b824801bf65a998253e0069449dd81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ReferenceCounter, :clean_gitlab_redis_shared_state do
  let(:reference_counter) { described_class.new('project-1') }

  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
  end

  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
      expect(Gitlab::AppLogger).to receive(:warn).with("Reference counter for project-1" \
        " decreased when its value was less than 1. Resetting the counter.")
      expect { reference_counter.decrease }.not_to change { reference_counter.value }
    end
  end

  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
  end

  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
  end

  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
  end
end