rspec-sidekiq icon indicating copy to clipboard operation
rspec-sidekiq copied to clipboard

Check if a job is scheduled for right now

Open dpoetzsch opened this issue 6 years ago • 2 comments

I'd expect the following to work (I am already wrapping this in timecop):

Timecop.freeze do
  Awesomejob.perform_in 0.seconds 'Awesome', true
  # test with...
  expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(0.seconds)
end

Well, it does not work leaving me with no way to check if the job was enqueued for now and not for a later time.

I already checked your code and I think the problem is that you directly return false if the sidekiq job is scheduled at nil, but I think nil should instead be treated as Time.now. If you're interested I can open a PR for this.

dpoetzsch avatar Aug 17 '17 15:08 dpoetzsch

Expect first

On Aug 17, 2017 11:37 AM, "David Poetzsch-Heffter" [email protected] wrote:

I'd expect the following to work (I am already wrapping this in timecop):

Timecop.freeze do Awesomejob.perform_in 0.seconds 'Awesome', true

test with...

expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(0.seconds)end

Am I missing something?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/philostler/rspec-sidekiq/issues/143, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGDd_4nwRdc91Pi5fC1lGL8p8xEluKvks5sZF42gaJpZM4O6cQY .

mathieujobin avatar Aug 18 '17 23:08 mathieujobin

Actually. I am not sure. I have no idea. Sorry.

On Aug 17, 2017 11:37 AM, "David Poetzsch-Heffter" [email protected] wrote:

I'd expect the following to work (I am already wrapping this in timecop):

Timecop.freeze do Awesomejob.perform_in 0.seconds 'Awesome', true

test with...

expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(0.seconds)end

Am I missing something?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/philostler/rspec-sidekiq/issues/143, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGDd_4nwRdc91Pi5fC1lGL8p8xEluKvks5sZF42gaJpZM4O6cQY .

mathieujobin avatar Aug 18 '17 23:08 mathieujobin

Late to the party but I think the matcher you're looking for is at e.g.,

Timecop.freeze do
  AwesomeJob.perform_in 0.seconds 'Awesome', true
  # test with...
  expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).at(Time.now)
end

I'm sure AwesomeJob.perform_in 0.seconds is contrived for this example... but just calling out that, if one wants something enqueued immediately, one should use perform_async not peform_in with a 0 length interval.

wspurgin avatar Aug 11 '23 19:08 wspurgin