summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/reference_counter_spec.rb
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-08-29 23:10:41 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-08-31 11:31:45 -0300
commiteaf60bb5441190e2ffcf219b3169bda2237d57cd (patch)
tree3139e8056df242472c91d9d2ac6d48c82cf4b36c /spec/lib/gitlab/reference_counter_spec.rb
parentcbaa015cc9f55a387cdab85a6ba4b8c9c6ab447e (diff)
downloadgitlab-ce-eaf60bb5441190e2ffcf219b3169bda2237d57cd.tar.gz
Implement /internal/post_receive unified endpoint for PostReceive tasksgitaly-shell-redis
Diffstat (limited to 'spec/lib/gitlab/reference_counter_spec.rb')
-rw-r--r--spec/lib/gitlab/reference_counter_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/lib/gitlab/reference_counter_spec.rb b/spec/lib/gitlab/reference_counter_spec.rb
new file mode 100644
index 00000000000..b2344d1870a
--- /dev/null
+++ b/spec/lib/gitlab/reference_counter_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Gitlab::ReferenceCounter do
+ let(:redis) { double('redis') }
+ let(:reference_counter_key) { "git-receive-pack-reference-counter:project-1" }
+ let(:reference_counter) { described_class.new('project-1') }
+
+ before do
+ allow(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis)
+ end
+
+ it 'increases and set the expire time of a reference count for a path' do
+ expect(redis).to receive(:incr).with(reference_counter_key)
+ expect(redis).to receive(:expire).with(reference_counter_key,
+ described_class::REFERENCE_EXPIRE_TIME)
+ expect(reference_counter.increase).to be(true)
+ end
+
+ it 'decreases the reference count for a path' do
+ allow(redis).to receive(:decr).and_return(0)
+ expect(redis).to receive(:decr).with(reference_counter_key)
+ expect(reference_counter.decrease).to be(true)
+ end
+
+ it 'warns if attempting to decrease a counter with a value of one or less, and resets the counter' do
+ expect(redis).to receive(:decr).and_return(-1)
+ expect(redis).to receive(:del)
+ expect(Rails.logger).to receive(:warn).with("Reference counter for project-1" \
+ " decreased when its value was less than 1. Reseting the counter.")
+ expect(reference_counter.decrease).to be(true)
+ end
+
+ it 'get the reference count for a path' do
+ allow(redis).to receive(:get).and_return(1)
+ expect(reference_counter.value).to be(1)
+ end
+end