diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-07-26 02:51:37 +0300 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-07-29 00:44:23 +0300 |
commit | bab49fdf9f27c44e830c470b749c5bc0022a25f5 (patch) | |
tree | 2636a4e3eae662495e423a019514f6c258d32053 /spec/lib/gitlab/backup | |
parent | 4c89929fb4211aa1cf5f311a0cec89988de45184 (diff) |
Protect backups from stale cache for repo exists
Diffstat (limited to 'spec/lib/gitlab/backup')
-rw-r--r-- | spec/lib/gitlab/backup/repository_spec.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/gitlab/backup/repository_spec.rb b/spec/lib/gitlab/backup/repository_spec.rb index db860b01ba4..79b0b5008c5 100644 --- a/spec/lib/gitlab/backup/repository_spec.rb +++ b/spec/lib/gitlab/backup/repository_spec.rb @@ -60,4 +60,58 @@ describe Backup::Repository do end end end + + describe '#empty_repo?' do + context 'for a wiki' do + let(:wiki) { create(:project_wiki) } + + context 'wiki repo has content' do + let!(:wiki_page) { create(:wiki_page, wiki: wiki) } + + before do + wiki.repository.exists? # initial cache + end + + context '`repository.exists?` is incorrectly cached as false' do + before do + repo = wiki.repository + repo.send(:cache).expire(:exists?) + repo.send(:cache).fetch(:exists?) { false } + repo.send(:instance_variable_set, :@exists, false) + end + + it 'returns false, regardless of bad cache value' do + expect(Backup::Repository.new.send(:empty_repo?, wiki)).to be_falsey + end + end + + context '`repository.exists?` is correctly cached as true' do + it 'returns false' do + expect(Backup::Repository.new.send(:empty_repo?, wiki)).to be_falsey + end + end + end + + context 'wiki repo does not have content' do + context '`repository.exists?` is incorrectly cached as true' do + before do + repo = wiki.repository + repo.send(:cache).expire(:exists?) + repo.send(:cache).fetch(:exists?) { true } + repo.send(:instance_variable_set, :@exists, true) + end + + it 'returns true, regardless of bad cache value' do + expect(Backup::Repository.new.send(:empty_repo?, wiki)).to be_truthy + end + end + + context '`repository.exists?` is correctly cached as false' do + it 'returns true' do + expect(Backup::Repository.new.send(:empty_repo?, wiki)).to be_truthy + end + end + end + end + end end |