timecop icon indicating copy to clipboard operation
timecop copied to clipboard

how to work with sidekiq?

Open TangMonk opened this issue 9 years ago • 6 comments

Timecop.freeze(Time.now + 1.hours) do
  ExpiredReserveWorker.perform_async
end

This above code not work

TangMonk avatar Jan 10 '16 12:01 TangMonk

Do you want to schedule a work to a sidekiq?

dmitry avatar Jan 11 '16 14:01 dmitry

yes, I have a sidekiq worker depend on time changes, I am writing a rspec with this gem to test this worker

TangMonk avatar Jan 11 '16 14:01 TangMonk

You have to use perform_in sidekiq method.

dmitry avatar Jan 11 '16 14:01 dmitry

I used perform_in(59.minutes) and after that ran Timecop.travel(1.hour) but the sidekiq task does not get executed :( - any ideas?

rgaufman avatar Jul 21 '18 15:07 rgaufman

Probably because it writes to redis time that are going to happen in the future, but the sidekiq knows nothing about the time travel thing, as it works with redis commands, instead of ruby environment.

dmitry avatar Jul 24 '18 21:07 dmitry

@rgaufman I would just write smaller unit tests. So for your thing enqueues a job (e.g. similar to https://github.com/mperham/sidekiq/wiki/Testing#testing-worker-queueing-fake), for example if you had a process that does MyWorker.perform_in(59.minutes), ensure that after it runs your MyWorker.jobs.size is one higher, but doesn't really care what MyWorker actually does. Then in another spec like myworker_spec.rb, have it just test #perform.

philihp avatar Aug 15 '18 21:08 philihp