diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/workers/concerns/application_worker_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/workers/concerns/application_worker_spec.rb')
-rw-r--r-- | spec/workers/concerns/application_worker_spec.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/workers/concerns/application_worker_spec.rb b/spec/workers/concerns/application_worker_spec.rb index ae311a54cd1..087a36d2bd0 100644 --- a/spec/workers/concerns/application_worker_spec.rb +++ b/spec/workers/concerns/application_worker_spec.rb @@ -118,5 +118,45 @@ describe ApplicationWorker do .to raise_error(ArgumentError) end end + + context 'with batches' do + let(:batch_delay) { 1.minute } + + it 'correctly schedules jobs' do + expect(Sidekiq::Client).to( + receive(:push_bulk).with(hash_including('args' => [['Foo', [1]], ['Foo', [2]]])) + .ordered + .and_call_original) + expect(Sidekiq::Client).to( + receive(:push_bulk).with(hash_including('args' => [['Foo', [3]], ['Foo', [4]]])) + .ordered + .and_call_original) + expect(Sidekiq::Client).to( + receive(:push_bulk).with(hash_including('args' => [['Foo', [5]]])) + .ordered + .and_call_original) + + worker.bulk_perform_in( + 1.minute, + [['Foo', [1]], ['Foo', [2]], ['Foo', [3]], ['Foo', [4]], ['Foo', [5]]], + batch_size: 2, batch_delay: batch_delay) + + expect(worker.jobs.count).to eq 5 + expect(worker.jobs[0]['at']).to eq(worker.jobs[1]['at']) + expect(worker.jobs[2]['at']).to eq(worker.jobs[3]['at']) + expect(worker.jobs[2]['at'] - worker.jobs[1]['at']).to eq(batch_delay) + expect(worker.jobs[4]['at'] - worker.jobs[3]['at']).to eq(batch_delay) + end + + context 'when batch_size is invalid' do + it 'raises an ArgumentError exception' do + expect do + worker.bulk_perform_in(1.minute, + [['Foo']], + batch_size: -1, batch_delay: batch_delay) + end.to raise_error(ArgumentError) + end + end + end end end |