1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Add the enqueued_at attribute when fake Testing (#3258)

Trying to emulate the real behavior, the job obtains an enqueued_at
attribute when it's placed in a queue.

Since using perform_in or perform_at does not put the job in the queue
when run, the attribute is not set for those methods.
This commit is contained in:
Fernando Seror Garcia 2016-11-25 23:19:16 -06:00 committed by Mike Perham
parent 2367bc19c1
commit 7a63036b21
2 changed files with 5 additions and 1 deletions

View file

@ -69,7 +69,9 @@ module Sidekiq
def raw_push(payloads)
if Sidekiq::Testing.fake?
payloads.each do |job|
Queues.push(job['queue'], job['class'], Sidekiq.load_json(Sidekiq.dump_json(job)))
job = Sidekiq.load_json(Sidekiq.dump_json(job))
job.merge!('enqueued_at' => Time.now.to_f) unless job['at']
Queues.push(job['queue'], job['class'], job)
end
true
elsif Sidekiq::Testing.inline?

View file

@ -61,8 +61,10 @@ class TestTesting < Sidekiq::Test
it 'stubs the async call' do
assert_equal 0, DirectWorker.jobs.size
assert DirectWorker.perform_async(1, 2)
assert_in_delta Time.now.to_f, DirectWorker.jobs.last['enqueued_at'], 0.01
assert_equal 1, DirectWorker.jobs.size
assert DirectWorker.perform_in(10, 1, 2)
refute DirectWorker.jobs.last['enqueued_at']
assert_equal 2, DirectWorker.jobs.size
assert DirectWorker.perform_at(10, 1, 2)
assert_equal 3, DirectWorker.jobs.size