diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-29 15:06:43 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-29 15:06:43 +0000 |
commit | eac0da9a47f0c7b8b970833d7d5b96cfee057bf7 (patch) | |
tree | 7b7865053435c6dcb4e2d945fcf45e309331c91b /spec/models/repository_spec.rb | |
parent | b860c6ba2607541e3b5bdf0fc2daaa9ed41a8726 (diff) | |
download | gitlab-ce-eac0da9a47f0c7b8b970833d7d5b96cfee057bf7.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r-- | spec/models/repository_spec.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index bad05990965..c0245dfdf1a 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2399,7 +2399,40 @@ describe Repository do end describe '#ancestor? with Gitaly enabled' do - it_behaves_like "#ancestor?" + let(:commit) { repository.commit } + let(:ancestor) { commit.parents.first } + let(:cache_key) { "ancestor:#{ancestor.id}:#{commit.id}" } + + it_behaves_like '#ancestor?' + + context 'caching', :request_store, :clean_gitlab_redis_cache do + it 'only calls out to Gitaly once' do + expect(repository.raw_repository).to receive(:ancestor?).once + + 2.times { repository.ancestor?(commit.id, ancestor.id) } + end + + it 'increments a counter with cache hits' do + counter = Gitlab::Metrics.counter(:repository_ancestor_calls_total, 'Repository ancestor calls') + + expect do + 2.times { repository.ancestor?(commit.id, ancestor.id) } + end.to change { counter.get(cache_hit: 'true') }.by(1) + .and change { counter.get(cache_hit: 'false') }.by(1) + end + + it 'returns the value from the request store' do + repository.__send__(:request_store_cache).write(cache_key, "it's apparent") + + expect(repository.ancestor?(ancestor.id, commit.id)).to eq("it's apparent") + end + + it 'returns the value from the redis cache' do + expect(repository.__send__(:cache)).to receive(:fetch).with(cache_key).and_return("it's apparent") + + expect(repository.ancestor?(ancestor.id, commit.id)).to eq("it's apparent") + end + end end describe '#ancestor? with Rugged enabled', :enable_rugged do |