debian-mirror-gitlab/spec/workers/expire_job_cache_worker_spec.rb

64 lines
2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ExpireJobCacheWorker do
2020-04-08 14:13:33 +05:30
let_it_be(:pipeline) { create(:ci_empty_pipeline) }
2017-08-17 22:00:37 +05:30
let(:project) { pipeline.project }
2020-01-01 13:55:28 +05:30
2017-08-17 22:00:37 +05:30
describe '#perform' do
context 'with a job in the pipeline' do
2021-04-29 21:17:54 +05:30
let_it_be(:job) { create(:ci_build, pipeline: pipeline) }
2020-04-08 14:13:33 +05:30
let(:job_args) { job.id }
include_examples 'an idempotent worker' do
it 'invalidates Etag caching for the job path' do
job_path = "/#{project.full_path}/builds/#{job.id}.json"
spy_store = Gitlab::EtagCaching::Store.new
allow(Gitlab::EtagCaching::Store).to receive(:new) { spy_store }
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
expect(spy_store).to receive(:touch)
.exactly(worker_exec_times).times
2021-04-17 20:07:23 +05:30
.with(job_path)
2020-04-08 14:13:33 +05:30
.and_call_original
2017-08-17 22:00:37 +05:30
2021-04-17 20:07:23 +05:30
expect(ExpirePipelineCacheWorker).to receive(:perform_async)
.with(pipeline.id)
2020-04-08 14:13:33 +05:30
.exactly(worker_exec_times).times
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
subject
end
2017-08-17 22:00:37 +05:30
end
2021-04-29 21:17:54 +05:30
it 'does not perform extra queries', :aggregate_failures do
worker = described_class.new
recorder = ActiveRecord::QueryRecorder.new { worker.perform(job.id) }
occurences = recorder.data.values.flat_map {|v| v[:occurrences]}
project_queries = occurences.select {|s| s.include?('FROM "projects"')}
namespace_queries = occurences.select {|s| s.include?('FROM "namespaces"')}
route_queries = occurences.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 <= 1
expect(project_queries.size).to eq(0)
expect(namespace_queries.size).to eq(0)
expect(route_queries.size).to eq(0)
end
2017-08-17 22:00:37 +05:30
end
context 'when there is no job in the pipeline' do
it 'does not change the etag store' do
expect(Gitlab::EtagCaching::Store).not_to receive(:new)
2020-04-22 19:07:51 +05:30
perform_multiple(non_existing_record_id)
2017-08-17 22:00:37 +05:30
end
end
end
end