2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
require 'rake_helper'
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
RSpec.describe 'clearing redis cache', :clean_gitlab_redis_repository_cache, :clean_gitlab_redis_cache,
|
2023-04-23 21:23:45 +05:30
|
|
|
:silence_stdout, :use_null_store_as_repository_cache, feature_category: :redis do
|
2018-10-15 14:42:47 +05:30
|
|
|
before do
|
|
|
|
Rake.application.rake_require 'tasks/cache'
|
|
|
|
end
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
let(:keys_size_changed) { -1 }
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
shared_examples 'clears the cache' do
|
2023-03-17 16:20:25 +05:30
|
|
|
it { expect { run_rake_task('cache:clear:redis') }.to change { redis_keys.size }.by(keys_size_changed) }
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
describe 'clearing pipeline status cache' do
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:pipeline_status) do
|
|
|
|
project = create(:project, :repository)
|
|
|
|
create(:ci_pipeline, project: project).project.pipeline_status
|
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
before do
|
|
|
|
allow(pipeline_status).to receive(:loaded).and_return(nil)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it_behaves_like 'clears the cache'
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'clearing set caches' do
|
|
|
|
context 'repository set' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
|
|
|
|
let(:cache) { Gitlab::RepositorySetCache.new(repository) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
cache.write(:foo, [:bar])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'clears the cache'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reactive cache set' do
|
|
|
|
let(:cache) { Gitlab::ReactiveCacheSetCache.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
cache.write(:foo, :bar)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'clears the cache'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redis_keys
|
|
|
|
Gitlab::Redis::Cache.with { |redis| redis.scan(0, match: "*") }.last
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|