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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/repository_cache/preloader_spec.rb')
-rw-r--r--spec/lib/gitlab/repository_cache/preloader_spec.rb89
1 files changed, 32 insertions, 57 deletions
diff --git a/spec/lib/gitlab/repository_cache/preloader_spec.rb b/spec/lib/gitlab/repository_cache/preloader_spec.rb
index 71244dd41ed..e6fb0da6412 100644
--- a/spec/lib/gitlab/repository_cache/preloader_spec.rb
+++ b/spec/lib/gitlab/repository_cache/preloader_spec.rb
@@ -6,76 +6,51 @@ RSpec.describe Gitlab::RepositoryCache::Preloader, :use_clean_rails_redis_cachin
feature_category: :source_code_management do
let(:projects) { create_list(:project, 2, :repository) }
let(:repositories) { projects.map(&:repository) }
+ let(:cache) { Gitlab::RepositoryCache.store }
- before do
- stub_feature_flags(use_primary_store_as_default_for_repository_cache: false)
- end
-
- shared_examples 'preload' do
- describe '#preload' do
- context 'when the values are already cached' do
- before do
- # Warm the cache but use a different model so they are not memoized
- repos = Project.id_in(projects).order(:id).map(&:repository)
-
- allow(repos[0]).to receive(:readme_path_gitaly).and_return('README.txt')
- allow(repos[1]).to receive(:readme_path_gitaly).and_return('README.md')
-
- repos.map(&:exists?)
- repos.map(&:readme_path)
- end
-
- it 'prevents individual cache reads for cached methods' do
- expect(cache).to receive(:read_multi).once.and_call_original
-
- described_class.new(repositories).preload(
- %i[exists? readme_path]
- )
-
- expect(cache).not_to receive(:read)
- expect(cache).not_to receive(:write)
+ describe '#preload' do
+ context 'when the values are already cached' do
+ before do
+ # Warm the cache but use a different model so they are not memoized
+ repos = Project.id_in(projects).order(:id).map(&:repository)
- expect(repositories[0].exists?).to eq(true)
- expect(repositories[0].readme_path).to eq('README.txt')
+ allow(repos[0].head_tree).to receive(:readme_path).and_return('README.txt')
+ allow(repos[1].head_tree).to receive(:readme_path).and_return('README.md')
- expect(repositories[1].exists?).to eq(true)
- expect(repositories[1].readme_path).to eq('README.md')
- end
+ repos.map(&:exists?)
+ repos.map(&:readme_path)
end
- context 'when values are not cached' do
- it 'reads and writes from cache individually' do
- described_class.new(repositories).preload(
- %i[exists? has_visible_content?]
- )
+ it 'prevents individual cache reads for cached methods' do
+ expect(cache).to receive(:read_multi).once.and_call_original
- expect(cache).to receive(:read).exactly(4).times
- expect(cache).to receive(:write).exactly(4).times
+ described_class.new(repositories).preload(
+ %i[exists? readme_path]
+ )
- repositories.each(&:exists?)
- repositories.each(&:has_visible_content?)
- end
- end
- end
- end
+ expect(cache).not_to receive(:read)
+ expect(cache).not_to receive(:write)
- context 'when use_primary_and_secondary_stores_for_repository_cache feature flag is enabled' do
- let(:cache) { Gitlab::RepositoryCache.store }
+ expect(repositories[0].exists?).to eq(true)
+ expect(repositories[0].readme_path).to eq('README.txt')
- before do
- stub_feature_flags(use_primary_and_secondary_stores_for_repository_cache: true)
+ expect(repositories[1].exists?).to eq(true)
+ expect(repositories[1].readme_path).to eq('README.md')
+ end
end
- it_behaves_like 'preload'
- end
+ context 'when values are not cached' do
+ it 'reads and writes from cache individually' do
+ described_class.new(repositories).preload(
+ %i[exists? has_visible_content?]
+ )
- context 'when use_primary_and_secondary_stores_for_repository_cache feature flag is disabled' do
- let(:cache) { Rails.cache }
+ expect(cache).to receive(:read).exactly(4).times
+ expect(cache).to receive(:write).exactly(4).times
- before do
- stub_feature_flags(use_primary_and_secondary_stores_for_repository_cache: false)
+ repositories.each(&:exists?)
+ repositories.each(&:has_visible_content?)
+ end
end
-
- it_behaves_like 'preload'
end
end