diff options
Diffstat (limited to 'spec/workers/concerns/waitable_worker_spec.rb')
-rw-r--r-- | spec/workers/concerns/waitable_worker_spec.rb | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/spec/workers/concerns/waitable_worker_spec.rb b/spec/workers/concerns/waitable_worker_spec.rb index 824ae8fcf83..f6d4cc4679d 100644 --- a/spec/workers/concerns/waitable_worker_spec.rb +++ b/spec/workers/concerns/waitable_worker_spec.rb @@ -29,40 +29,41 @@ RSpec.describe WaitableWorker do subject(:job) { worker.new } describe '.bulk_perform_and_wait' do - it 'schedules the jobs and waits for them to complete' do - worker.bulk_perform_and_wait([[1], [2]]) - - expect(worker.counter).to eq(3) + context '1 job' do + it 'inlines the job' do + args_list = [[1]] + expect(worker).to receive(:bulk_perform_inline).with(args_list).and_call_original + expect(Gitlab::AppJsonLogger).to( + receive(:info).with(a_hash_including('message' => 'running inline', + 'class' => 'Gitlab::Foo::Bar::DummyWorker', + 'job_status' => 'running', + 'queue' => 'foo_bar_dummy')) + .once) + + worker.bulk_perform_and_wait(args_list) + + expect(worker.counter).to eq(1) + end end - it 'inlines workloads <= 3 jobs' do - args_list = [[1], [2], [3]] - expect(worker).to receive(:bulk_perform_inline).with(args_list).and_call_original - expect(Gitlab::AppJsonLogger).to( - receive(:info).with(a_hash_including('message' => 'running inline', - 'class' => 'Gitlab::Foo::Bar::DummyWorker', - 'job_status' => 'running', - 'queue' => 'foo_bar_dummy')) - .exactly(3).times) - - worker.bulk_perform_and_wait(args_list) + context 'between 2 and 3 jobs' do + it 'runs the jobs asynchronously' do + arguments = [[1], [2], [3]] - expect(worker.counter).to eq(6) - end - - it 'runs > 3 jobs using sidekiq and a waiter key' do - expect(worker).to receive(:bulk_perform_async) - .with([[1, anything], [2, anything], [3, anything], [4, anything]]) + expect(worker).to receive(:bulk_perform_async).with(arguments) - worker.bulk_perform_and_wait([[1], [2], [3], [4]]) + worker.bulk_perform_and_wait(arguments) + end end - it 'runs > 10 * timeout jobs using sidekiq and no waiter key' do - arguments = 1.upto(21).map { |i| [i] } + context '>= 4 jobs' do + it 'runs jobs using sidekiq' do + arguments = 1.upto(5).map { |i| [i] } - expect(worker).to receive(:bulk_perform_async).with(arguments) + expect(worker).to receive(:bulk_perform_async).with(arguments) - worker.bulk_perform_and_wait(arguments, timeout: 2) + worker.bulk_perform_and_wait(arguments) + end end end |