Sha256: 3cd70f4f77470f959614e3b87fdc34720d007eb779c5ee4905071e4340bbbc07

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

class WorkerTest < LocaljobTestCase
  def setup
    @localjob = queue
    @worker   = worker
  end

  def test_pop_and_send_to_worker
    WalrusJob.any_instance.expects(:perform)

    @localjob << WalrusJob.new("move")

    job = @localjob.shift
    @worker.process(job)
  end

  def test_working_off_queue_in_child
    @localjob << WalrusJob.new("move")

    fork do
      job = @localjob.shift
      @worker.process(job)
    end

    Process.wait
    assert_equal 0, @localjob.size
  end

  def test_sigquit_terminates_the_worker
    @localjob << WalrusJob.new("move")

    assert_equal 1, @localjob.size

    pid = fork { @worker.work }

    Process.kill("QUIT", pid)
    Process.wait

    assert_equal 0, @localjob.size
  end

  def test_doesnt_stop_on_error
    @localjob << AngryWalrusJob.new(100)
    @localjob << WalrusJob.new("be happy")

    pid = fork { @worker.work }

    # Hack to account for race condition, 0.01s should be plenty
    sleep 0.01
    Process.kill("QUIT", pid)
    Process.wait

    assert_equal 0, @localjob.size
  end

  def test_workers_listen_on_multiple_queues
    @localjob << WalrusJob.new("move")

    other = queue("other-queue")
    other << WalrusJob.new("dance")

    @worker.channel << 'other-queue'

    pid = fork { @worker.work }

    # Hack to account for race condition, 0.01s should be plenty
    sleep 0.01
    Process.kill("QUIT", pid)
    Process.wait

    assert_equal 0, @localjob.size
    assert_equal 0, other.size
  end

  def test_worker_doesnt_die_on_bad_serialization
    @localjob.queue.timedsend "--- !ruby/object:Whatever {}\n"

    pid = fork { @worker.work }

    sleep 0.01
    Process.kill("QUIT", pid)
    Process.wait
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localjob-0.0.1 test/worker_test.rb