wspurgin / rspec-sidekiq

RSpec for Sidekiq
https://github.com/wspurgin/rspec-sidekiq
Other
651 stars 133 forks source link

Check if a job is scheduled for right now #143

Closed dpoetzsch closed 10 months ago

dpoetzsch commented 6 years ago

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.

mathieujobin commented 6 years ago

Expect first

On Aug 17, 2017 11:37 AM, "David Poetzsch-Heffter" notifications@github.com 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 commented 6 years ago

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

On Aug 17, 2017 11:37 AM, "David Poetzsch-Heffter" notifications@github.com 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 .

wspurgin commented 10 months ago

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.