summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2018-09-25 10:12:51 -0700
committerMichael Kozono <mkozono@gmail.com>2018-09-27 18:22:37 -0700
commit3640292bf2ef822c8e2394fa2397b1b7d04e9891 (patch)
treee6083dca766e7acfb94b613329a43c98a8aa526b /spec/models
parentd9c4ebc5a0b2e911f17865e482de1dfcc2189ac3 (diff)
downloadgitlab-ce-3640292bf2ef822c8e2394fa2397b1b7d04e9891.tar.gz
Cache `Repository#exists?` false in RequestStore
* Only truthy values are cached in Redis. * All values are cached in RequestStore and in an instance variable.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/repository_spec.rb43
1 files changed, 42 insertions, 1 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index dffac05152b..b2869104e02 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1044,6 +1044,47 @@ describe Repository do
expect_to_raise_storage_error { broken_repository.exists? }
end
end
+
+ context 'asymmetric caching', :use_clean_rails_memory_store_caching, :request_store do
+ let(:cache) { repository.send(:cache) }
+ let(:request_store_cache) { repository.send(:request_store_cache) }
+
+ context 'when it returns true' do
+ before do
+ expect(repository.raw_repository).to receive(:exists?).once.and_return(true)
+ end
+
+ it 'caches the output in RequestStore' do
+ expect do
+ repository.exists?
+ end.to change { request_store_cache.read(:exists?) }.from(nil).to(true)
+ end
+
+ it 'caches the output in RepositoryCache' do
+ expect do
+ repository.exists?
+ end.to change { cache.read(:exists?) }.from(nil).to(true)
+ end
+ end
+
+ context 'when it returns false' do
+ before do
+ expect(repository.raw_repository).to receive(:exists?).once.and_return(false)
+ end
+
+ it 'caches the output in RequestStore' do
+ expect do
+ repository.exists?
+ end.to change { request_store_cache.read(:exists?) }.from(nil).to(false)
+ end
+
+ it 'does NOT cache the output in RepositoryCache' do
+ expect do
+ repository.exists?
+ end.not_to change { cache.read(:exists?) }.from(nil)
+ end
+ end
+ end
end
describe '#has_visible_content?' do
@@ -1892,7 +1933,7 @@ describe Repository do
match[1].to_sym if match
end.compact
- expect(methods).to match_array(Repository::CACHED_METHODS + Repository::MEMOIZED_CACHED_METHODS)
+ expect(Repository::CACHED_METHODS + Repository::MEMOIZED_CACHED_METHODS).to include(*methods)
end
end