Commit 7fe9058c authored by Kerri Miller's avatar Kerri Miller

Scope tests against DeprecatedHighlightCache

parent baedc099
......@@ -29,13 +29,19 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let(:diffable) { merge_request.merge_request_diff }
end
it 'uses a different cache key if diff line keys change' do
mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil)
key = mr_diff.cache_key
context 'using Gitlab::Diff::DeprecatedHighlightCache' do
before do
stub_feature_flags(redis_diff_caching: false)
end
it 'uses a different cache key if diff line keys change' do
mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil)
key = mr_diff.cache_key
stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo])
stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo])
expect(mr_diff.cache_key).not_to eq(key)
expect(mr_diff.cache_key).not_to eq(key)
end
end
it_behaves_like 'diff statistics' do
......
......@@ -33,13 +33,34 @@ describe MergeRequests::ReloadDiffsService, :use_clean_rails_memory_store_cachin
end
context 'cache clearing' do
it 'clears the cache for older diffs on the merge request' do
old_diff = merge_request.merge_request_diff
old_cache_key = old_diff.diffs_collection.cache_key
context 'using Gitlab::Diff::DeprecatedHighlightCache' do
before do
stub_feature_flags(redis_diff_caching: false)
end
expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original
it 'clears the cache for older diffs on the merge request' do
old_diff = merge_request.merge_request_diff
old_cache_key = old_diff.diffs_collection.cache_key
subject.execute
expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original
subject.execute
end
end
context 'using Gitlab::Diff::HighlightCache' do
before do
stub_feature_flags(redis_diff_caching: true)
end
it 'clears the cache for older diffs on the merge request' do
old_diff = merge_request.merge_request_diff
old_cache_key = old_diff.diffs_collection.cache_key
expect_any_instance_of(Redis).to receive(:del).with(old_cache_key).and_call_original
subject.execute
end
end
it 'avoids N+1 queries', :request_store do
......
......@@ -87,10 +87,28 @@ describe Notes::CreateService do
.to receive(:unfolded_diff?) { true }
end
it 'clears noteable diff cache when it was unfolded for the note position' do
expect_any_instance_of(Gitlab::Diff::DeprecatedHighlightCache).to receive(:clear)
context 'using Gitlab::Diff::DeprecatedHighlightCache' do
before do
stub_feature_flags(redis_diff_caching: false)
end
it 'clears noteable diff cache when it was unfolded for the note position' do
expect_any_instance_of(Gitlab::Diff::DeprecatedHighlightCache).to receive(:clear)
described_class.new(project_with_repo, user, new_opts).execute
end
end
described_class.new(project_with_repo, user, new_opts).execute
context 'using Gitlab::Diff::HighlightCache' do
before do
stub_feature_flags(redis_diff_caching: true)
end
it 'clears noteable diff cache when it was unfolded for the note position' do
expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear)
described_class.new(project_with_repo, user, new_opts).execute
end
end
it 'does not clear cache when note is not the first of the discussion' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment