amitree / delayed_job_recurring

Extends delayed_job to support recurring jobs
MIT License
84 stars 33 forks source link

Endless loop with RSpec #11

Closed ghost closed 7 years ago

ghost commented 8 years ago

I'm using delayed_job_active_record and delayed_job_recurring. Everything works great in development and production. However, in test environment I'm getting Stack level too deep exception when testing recurring jobs.

I configured Delayed job to work synchronously when running specs:

Delayed::Worker.delay_jobs = false

My current (not so great) workaround is to include RecurringJob only outside of test env:

class MyRecurringJob
    unless Rails.env.test?
        include Delayed::RecurringJob
        run_every 5.minutes
    end

# ...

end

I'm using:

ericchapman commented 7 years ago

I ended up surrounding my config/initializer file as follows

if Rails.env.production?
  MyJob.schedule!
end

and then just calling my scheduled jobs manually in Rspec

it 'performs the job' do
  MyJob.perform
end

This allowed me to test the work that the job was doing by bypassing the scheduled aspect of it.