Sha256: 4017543d434bd9faa7475cf0ca838e7b2070e0cab1f81eeee8c469ec7edf2ad1

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

class TestHandler < PerfectSched::Application::Base
  def run
    puts "TestHandler: #{task}"
    if task.data['raise_error']
      raise "expected error test"
    end
    if num = task.data['sleep']
      sleep num
    end
    puts "Task finished"
  end

  def kill(reason)
    puts "kill: #{reason.class}: #{reason}"
  end
end

class TestApp < PerfectSched::Application::Dispatch
  route 'test' => TestHandler
end

describe Worker do
  before do
    create_test_sched.close
    @worker = Worker.new(TestApp, test_sched_config)
    @thread = Thread.new {
      @worker.run
    }
  end

  after do
    @worker.stop
    @thread.join
  end

  def add(*args)
    sc = get_test_sched
    sc.add(*args)
    sc.close
  end

  it 'run' do
    TestHandler.any_instance.should_receive(:run).once
    add('key', 'test', {:cron=>'* * * * *', :next_time=>Time.now.to_i-60})
    sleep 2
  end

  it 'term signal' do
    sleep 1
    Process.kill(:TERM, Process.pid)
    puts "finish expected..."
    @thread.join
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
perfectsched-0.8.10 spec/worker_spec.rb
perfectsched-0.8.9 spec/worker_spec.rb