diff options
Diffstat (limited to 'spec/workers/pipeline_schedule_worker_spec.rb')
-rw-r--r-- | spec/workers/pipeline_schedule_worker_spec.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/workers/pipeline_schedule_worker_spec.rb b/spec/workers/pipeline_schedule_worker_spec.rb index 48138034c33..5648c5bc4c5 100644 --- a/spec/workers/pipeline_schedule_worker_spec.rb +++ b/spec/workers/pipeline_schedule_worker_spec.rb @@ -14,13 +14,15 @@ RSpec.describe PipelineScheduleWorker, :sidekiq_inline, feature_category: :conti create(:ci_pipeline_schedule, :nightly, project: project, owner: user) end + let(:next_run_at) { pipeline_schedule.next_run_at } + before do stub_application_setting(auto_devops_enabled: false) stub_ci_pipeline_to_return_yaml_file end around do |example| - travel_to(pipeline_schedule.next_run_at + 1.hour) do + travel_to(next_run_at + 1.hour) do example.run end end @@ -142,4 +144,52 @@ RSpec.describe PipelineScheduleWorker, :sidekiq_inline, feature_category: :conti expect { subject }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError) end end + + context 'with scheduling delay' do + before do + stub_const("#{described_class}::BATCH_SIZE", 1) + end + + let!(:other_pipeline_schedule) do + create(:ci_pipeline_schedule, :every_minute, project: project, owner: user) + end + + let(:next_run_at) do + [pipeline_schedule, other_pipeline_schedule].maximum(:next_run_at) + end + + it 'calls bulk_perform_in with the arguments and delay' do + expect(RunPipelineScheduleWorker) + .to receive(:bulk_perform_in) + .with(1.second, [[pipeline_schedule.id, user.id, { scheduling: true }]]) + .and_call_original + + expect(RunPipelineScheduleWorker) + .to receive(:bulk_perform_in) + .with(7.seconds, [[other_pipeline_schedule.id, user.id, { scheduling: true }]]) + .and_call_original + + subject + end + + context 'with run_pipeline_schedule_worker_with_delay disabled' do + before do + stub_feature_flags(run_pipeline_schedule_worker_with_delay: false) + end + + it 'calls bulk_perform_async with the arguments and delay' do + expect(RunPipelineScheduleWorker) + .to receive(:bulk_perform_async) + .with([[pipeline_schedule.id, user.id, { scheduling: true }]]) + .and_call_original + + expect(RunPipelineScheduleWorker) + .to receive(:bulk_perform_async) + .with([[other_pipeline_schedule.id, user.id, { scheduling: true }]]) + .and_call_original + + subject + end + end + end end |