Search code examples
ruby-on-railsrufus-schedulerdashing

Rufus scheduler Timeout::Error on Selenium Specs


I'm using dashing-rails https://github.com/gottfrois/dashing-rails in my project. It runs rufus-scheduler jobs on rails env load.

When I run my integration tests (rspec, capybara, selenium-driver), some of my tests randomly fail due to rufus-scheduler timeout errors. Is there a way to silence rufus-scheduler errors or disable rufus altogether in the test environment? I am not a fan of doing rails_env=test on my code base so any other solution would be appreciated.

Sample errors look like the following:

{ 283064 rufus-scheduler intercepted an error:
  283064   job:
  283064     Rufus::Scheduler::EveryJob "10s" {}
  283064   error:
  283064     283064
  283064     Timeout::Error
  283064     Waited 3 sec

Solution

  • The rufus-scheduler #on_error could help. It's documented at https://github.com/jmettraux/rufus-scheduler#rufusscheduleron_errorjob-error

    For example:

    if rails_env == 'test' # set the handler only when testing...
      def Dashing.scheduler.on_error(job, error)
        # keep silent, do nothing
      end
    end
    

    You seem not to want to set the Rails env to "test" for your integration test so you have to find a way to determine when to override the scheduler #on_error method, that's your problem.

    Also, rufus-scheduler doesn't raise instances of Timeout::Error, it raises instances of Rufus::Scheduler::TimeoutError so the errors you are seeing are not rufus-scheduler errors, they are merely intercepted by rufus-scheduler.

    As commented above, as the author of rufus-scheduler, I did not write rufus-scheduler to read titles like "Rufus scheduler breaking integration tests", YOUR code assemblage breaks YOUR integration tests. Do take responsibility.