2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-04 15:38:16 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ExpirePipelineCacheWorker do
|
2020-02-13 18:09:00 +00:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
subject { described_class.new }
|
2017-04-04 15:38:16 +00:00
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
describe '#perform' do
|
2019-04-12 19:29:47 +00:00
|
|
|
it 'executes the service' do
|
2020-04-21 15:21:10 +00:00
|
|
|
expect_next_instance_of(Ci::ExpirePipelineCacheService) do |instance|
|
|
|
|
expect(instance).to receive(:execute).with(pipeline).and_call_original
|
|
|
|
end
|
2017-04-20 06:44:01 +00:00
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
|
2021-03-26 21:09:22 +00:00
|
|
|
it 'does not perform extra queries', :aggregate_failures do
|
|
|
|
recorder = ActiveRecord::QueryRecorder.new { subject.perform(pipeline.id) }
|
|
|
|
|
|
|
|
project_queries = recorder.data.values.flat_map {|v| v[:occurrences]}.select {|s| s.include?('FROM "projects"')}
|
|
|
|
namespace_queries = recorder.data.values.flat_map {|v| v[:occurrences]}.select {|s| s.include?('FROM "namespaces"')}
|
|
|
|
route_queries = recorder.data.values.flat_map {|v| v[:occurrences]}.select {|s| s.include?('FROM "routes"')}
|
|
|
|
|
|
|
|
# This worker is run 1 million times an hour, so we need to save as much
|
|
|
|
# queries as possible.
|
|
|
|
expect(recorder.count).to be <= 6
|
|
|
|
|
|
|
|
# These arises from #update_etag_cache
|
|
|
|
expect(project_queries.size).to eq(1)
|
|
|
|
expect(namespace_queries.size).to eq(1)
|
|
|
|
expect(route_queries.size).to eq(1)
|
|
|
|
end
|
|
|
|
|
2017-04-21 15:39:19 +00:00
|
|
|
it "doesn't do anything if the pipeline not exist" do
|
2019-04-12 19:29:47 +00:00
|
|
|
expect_any_instance_of(Ci::ExpirePipelineCacheService).not_to receive(:execute)
|
2017-04-21 15:39:19 +00:00
|
|
|
expect_any_instance_of(Gitlab::EtagCaching::Store).not_to receive(:touch)
|
|
|
|
|
|
|
|
subject.perform(617748)
|
|
|
|
end
|
2020-02-13 18:09:00 +00:00
|
|
|
|
2021-06-14 15:09:48 +00:00
|
|
|
skip "with https://gitlab.com/gitlab-org/gitlab/-/issues/325291 resolved" do
|
|
|
|
it_behaves_like 'an idempotent worker' do
|
|
|
|
let(:job_args) { [pipeline.id] }
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
2021-06-14 15:09:48 +00:00
|
|
|
|
|
|
|
it_behaves_like 'worker with data consistency',
|
|
|
|
described_class,
|
|
|
|
data_consistency: :delayed
|
2017-04-04 15:38:16 +00:00
|
|
|
end
|
|
|
|
end
|