Sha256: 05d2286eb4560d5c040b19f2476a5c19a35e7974f490fa70640f9404fa8a10cd

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

require 'test_helper'

class WorkerTest < LocaljobTestCase
  def setup
    @localjob = queue
    @worker   = worker(@localjob)
  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")

    a = Thread.start {
      job = @localjob.shift
      @worker.process(job)
    }

    a.join

    assert_equal 0, @localjob.size
  end


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

    @worker.work(thread: true)

    sleep 0.1
    @worker.kill

    assert_equal 0, @localjob.size
  end

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

    @worker.work(thread: true)
    sleep 0.1
    @worker.kill
  end

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

    assert_equal 1, @localjob.size

    pid = fork { @worker.work }
    sleep 0.1

    Process.kill("QUIT", pid)

    assert_equal 0, @localjob.size
  end

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

    pid = fork { @worker.work }
    sleep 0.1

    Process.kill("INT", pid)
  end

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

    assert_equal 1, @localjob.size

    @worker.work(thread: true)
    sleep 0.1
    @worker.kill

    assert_equal 0, @localjob.size
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
localjob-0.3.0 test/worker_test.rb
localjob-0.2.0 test/worker_test.rb