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

Version Path
perfectqueue-0.8.44.1 spec/supervisor_spec.rb
perfectqueue-0.8.44 spec/supervisor_spec.rb
perfectqueue-0.8.43 spec/supervisor_spec.rb
perfectqueue-0.8.42 spec/supervisor_spec.rb
perfectqueue-0.8.41 spec/supervisor_spec.rb
perfectqueue-0.8.40 spec/supervisor_spec.rb
perfectqueue-0.8.39 spec/supervisor_spec.rb
perfectqueue-0.8.38 spec/supervisor_spec.rb
perfectqueue-0.8.37 spec/supervisor_spec.rb
perfectqueue-0.8.36 spec/supervisor_spec.rb
perfectqueue-0.8.35 spec/supervisor_spec.rb
perfectqueue-0.8.34 spec/supervisor_spec.rb
perfectqueue-0.8.33 spec/supervisor_spec.rb
perfectqueue-0.8.32 spec/supervisor_spec.rb
perfectqueue-0.8.31 spec/supervisor_spec.rb
perfectqueue-0.8.30 spec/supervisor_spec.rb
perfectqueue-0.8.29 spec/supervisor_spec.rb
perfectqueue-0.8.28 spec/supervisor_spec.rb
perfectqueue-0.8.26 spec/supervisor_spec.rb
perfectqueue-0.8.25 spec/supervisor_spec.rb