Skip to content

Commit

Permalink
Add aggressive test for async Batches (#833)
Browse files Browse the repository at this point in the history
* Add aggressive test for async Batches

* More sleep, more errors, more thread concurrency
  • Loading branch information
bensheldon authored Mar 8, 2023
1 parent 7645cb3 commit 575d0d8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/integration/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,35 @@ def perform(*_args, **_kwargs)
expect(callback_arguments).to contain_exactly({ event: :success }, { event: :finish })
end
end

describe 'aggressive async batching' do
it 'can execute multiple jobs' do
allow(GoodJob.configuration).to receive(:max_threads).and_return(20)
capsule = GoodJob::Capsule.new(configuration: GoodJob.configuration)
adapter = GoodJob::Adapter.new(execution_mode: :async_all, _capsule: capsule)

ActiveJob::Base.queue_adapter = adapter
expect(ActiveJob::Base.queue_adapter.execute_async?).to be true

stub_const 'TestJob', (Class.new(ActiveJob::Base) do
retry_on('ExpectedError', wait: 0, attempts: 2) { nil }

def perform(id)
sleep(1)
raise ExpectedError if rand(10) == 1
raise ExpectedError if id == 25
end
end)

batch = GoodJob::Batch.new
batch.on_discard = "BatchCallbackJob"
batch.on_finish = "BatchCallbackJob"
batch.enqueue do
50.times { |i| TestJob.perform_later(i) }
end

wait_until(max: 30) { expect(GoodJob::Job.finished.count).to eq 52 }
capsule.shutdown(timeout: -1)
end
end
end

0 comments on commit 575d0d8

Please sign in to comment.