Sha256: 07bf94acc7cce80cfdea64529b203db23fd96fe4a188cb2d0ac6174cc22f5ad4

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# vim:fileencoding=utf-8
require_relative 'test_helper'

context 'Resque::Scheduler' do
  setup do
    Resque::Scheduler.configure do |c|
      c.dynamic = false
      c.poll_sleep_amount = 0.1
    end
    Resque.redis.flushall
    Resque::Scheduler.quiet = true
    Resque::Scheduler.clear_schedule!
    Resque::Scheduler.send(:instance_variable_set, :@scheduled_jobs, {})
    Resque::Scheduler.send(:instance_variable_set, :@shutdown, false)
  end

  test 'shutdown raises Interrupt when sleeping' do
    Thread.current.expects(:raise).with(Interrupt)
    Resque::Scheduler.send(:instance_variable_set, :@th, Thread.current)
    Resque::Scheduler.send(:instance_variable_set, :@sleeping, true)
    Resque::Scheduler.shutdown
  end

  test 'sending TERM to scheduler breaks out of poll_sleep' do
    Resque::Scheduler.expects(:release_master_lock)

    @pid = Process.pid
    Thread.new do
      sleep(0.05)
      Process.kill(:TERM, @pid)
    end

    assert_raises SystemExit do
      Resque::Scheduler.run
    end

    Resque::Scheduler.unstub(:release_master_lock)
    Resque::Scheduler.release_master_lock
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resque-scheduler-4.1.0 test/scheduler_task_test.rb
resque-scheduler-4.0.0 test/scheduler_task_test.rb
resque-scheduler-3.1.0 test/scheduler_task_test.rb