I am using rails5 and activejobs and I am trying to enqueue a job after a specific time(2 hours). Im currently testing the Background jobs and I am using Timecop to change the time 2 hours later. How to make sure that workers are running in the test environment? This is the code that calls the job:
def send_missed_session_email
message = self
SendingMissedMessageJob.set(queue: :message_queue, wait_until: message.created_at + 2.hours).perform_later(message)
end
This is the job's code
def perform(message)
@recepient = message.recepient
@sender = message.sender
@content = message.message
UserMailer.send_notify_message_email(@recepient,@sender, @content).deliver_later
end
This is the test code:
it "sends send_notify_message_email email after 5 hrs from the message creation" do
Timecop.travel(message.created_at + 5.hours)
perform_enqueued_jobs do
end
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
Failures:
1) SendingMissedMessageJob sends send_notify_message_email email after 5 hrs from the message creation Failure/Error: expect(ActionMailer::Base.deliveries.count).to eq(1)
expected: 1
got: 0
(compared using ==)
Aucun commentaire:
Enregistrer un commentaire