delayed_job icon indicating copy to clipboard operation
delayed_job copied to clipboard

Disable handle_asynchronously in test mode

Open jonleighton opened this issue 16 years ago • 4 comments

If you're using handle_asynchronously, I think it's reasonable to assume that you want the delaying behaviour to be "transparent" within your app. Therefore, in test mode, the relevant methods should not actually become a delayed job.

I'm achieving this currently using:

# Disable transparent delayed_job methods in test mode
module Delayed::MessageSending
  def send_later(method, *args)
    send(method, *args)
  end
end

This has the side effect of also disabling send_later. I have mixed feelings about whether that should actually happen, as it's a more explicit call, so would be interested in thoughts on that.

jonleighton avatar Aug 22 '09 13:08 jonleighton

What about only calling #handle_asynchronously if you're in test mode?

def do_something
  # here
end
handle_asynchronously :do_something unless Rails.env.test?

Or less intrusive…make all of your #handle_asynchronously calls in config/environments/production.rb?

bkeepers avatar Aug 24 '09 16:08 bkeepers

Hmm. The first solution isn't great because rcov will report that line as un-tested. The second - I'd prefer not as this is something which will easily confuse somebody who hasn't seen the codebase before.

jonleighton avatar Aug 24 '09 16:08 jonleighton

I test this behaviour by ensuring that calling the method which is to be handled asynchronously returns an instance of Delayed::Backend::ActiveRecord::Job, then I test the method itself by calling invoke_job on the Delayed::Backend::ActiveRecord::Job instance

ciaranlee avatar Oct 05 '10 16:10 ciaranlee

I think this is fixed by Delayed::Worker.delay_jobs = false

Was having a separate issue with my delayed jobs and got to this PR and ended up digging around in the wrong direction for a bit- probably worth closing!

samanthamjohn avatar Nov 12 '14 21:11 samanthamjohn