Sha256: ccb69017fc8a3d67a592939069152be1694448bfc7d026f3e8b3c2b62e44533f
Contents?: true
Size: 1.52 KB
Versions: 33
Compression:
Stored size: 1.52 KB
Contents
require 'spec_helper' class TestHandler < PerfectQueue::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 RegexpHandler < PerfectQueue::Application::Base def run puts "RegexpHandler: #{task}" end end class TestApp < PerfectQueue::Application::Dispatch route 'test' => TestHandler route /reg.*/ => RegexpHandler end describe Supervisor do include QueueTest before do @sv = Supervisor.new(TestApp, queue_config) @thread = Thread.new { @sv.run } end after do @sv.stop(true) @thread.join end it 'route' do TestHandler.any_instance.should_receive(:run).once RegexpHandler.any_instance.should_receive(:run).once queue.submit('task01', 'test', {}) queue.submit('task02', 'reg01', {}) sleep 1 end it 'term signal' do sleep 1 Process.kill(:TERM, Process.pid) puts "finish expected..." @thread.join end it 'quit signal' do sleep 1 Process.kill(:QUIT, Process.pid) puts "finish expected..." @thread.join end it 'kill reason' do TestHandler.any_instance.should_receive(:kill).once #.with(kind_of(PerfectQueue::CancelRequestedError)) # FIXME 'with' dead locks queue.submit('task01', 'test', {'sleep'=>4}) sleep 2 Process.kill(:TERM, Process.pid) @thread.join end end
Version data entries
33 entries across 33 versions & 1 rubygems