New Matcher Idea: have_enqueued_jobs_in_bulk
While working on my gem: http://sidekiq-orm.github.io
I wanted to be able to test Sidekiq::ActiveRecord::ManagerWorker, which uses Sidekiq::Client.push_bulk, e.g
def batch_args(*ids)
{class: custom_worker_class, args: ids.map{ |id| [id] }}
end
context 'as method arguments' do
it 'pushes a bulk of all user ids for the specified worker_class' do
expect(sidekiq_client).to receive(:push_bulk).with( batch_args(user_1.id, user_2.id, user_3.id) )
run_worker({:worker_class => custom_worker_class})
end
end
from: https://github.com/sidekiq-orm/sidekiq-activerecord/blob/master/spec/sidekiq/active_record/manager_worker_spec.rb#L77-L87
It would be great if I could do:
expect(custom_worker_class).to have_enqueued_jobs_in_bulk([ [id1], [id2] ])
for more info on Sidekiq::ActiveRecord::ManagerWorker :
https://github.com/sidekiq-orm/sidekiq-activerecord/wiki/Manager-Worker
https://github.com/sidekiq-orm/sidekiq-activerecord/blob/master/lib/sidekiq/active_record/manager_worker.rb
@philostler WDYT?
9 years later but... I know we can test this today with something like:
expect(custom_worker_class.jobs.size).to eq(users.count)
users.each do |user|
expect(custom_worker_class).to have_enqueued_sidekiq_job(user.id)
end
But I get that such an approach is maybe overly verbose. I don't know that I want to support something that specifically checks for "was this enqueued with a bulk push?" as the name of this issues suggests... but having composable matchers and a way to specify "I want a job with arg i in array of args" makes some sense e.g., something like
expect { some_service.call }.to enqueue_sidekiq_job(AwesomeJob).per(users.map(&:id))