Test priorities for delayed_job plugin in rails

I want to check how the priorities work in the delayed_job plugin. I am using mailit app from railscasts . I think I want to send 100 messages with high priority and 100 with lower priority. And I want to see if lower priority messages are delivered on time or delayed.

How can I make a test like this.

+2


source to share


3 answers


Making a test like this shouldn't be a big problem. Create 100 high priority emails, then 100 low ones. Or vice versa. Don't run your workers until you check the database to make sure every job is there and accounted for. Get started with youR workers and see how the jobs get done - and in the right order. Remember that priority in d_j is increasing, so priority 1 is higher than 10.



Now 200 tasks is not a lot. Your employees are likely to complete them all quickly. If you really want to check if your emails are being sent with low priority, you will probably depend on what else you receive in your queue - provided that you use d_j for more than just email. I would suggest filling the queue with at least a few thousand jobs, or whatever you foresee the "worst case scenario" - and test with that. If non-email jobs have a higher priority than low priority emails, they are more likely to affect email delivery than high priority 100.

+1


source


If you're curious about how quickly these emails will be available to real recipients, you can simply do one thing: send these emails. Without actually going through the full delivery process, it is absolutely impossible to determine how many of these emails will be delayed due to greylisting, MX crashes, overloaded MXs, broken content scanners (or worse, broken content scanners in SMTP proxy mode), broken connection to The Internet on receiving servers, etc.



0


source


I actually did a test to test the DelayedJob handling by sending emails. The test is actually pretty simple.

You have to queue 2 jobs (instead of 100), one with a high priority and one with a lower priority. Then you can use the "Delayed :: Job.work_off" method to execute the first job and then assert that the lower priority job is still pending db. If you're still not sure how to get the job done, take a look at the library. The code is pretty well written.

Here is a code snippet from my application. Basically I need to send reminder emails to users, so I need to make sure the tasks are done correctly and the email program isn't bombing. I put this test in the reminder_test.rb unit test file as the Reminder model knows all about how to insert and send emails.

# enqueue the jobs here

assert_difference 'Delayed::Job.count', -1, 'Job should execute successfully' do
  assert_difference 'ActionMailer::Base.deliveries.count' do
    Delayed::Job.work_off
  end 
end

# make sure the email was properly delivered
email = ActionMailer::Base.deliveries.last
assert_equal email.to[0], @user.email
assert (Time.now - @reminder.reload.sent_at) < 1.seconds

      

Hooray! We hope for this help.

Alex

0


source







All Articles