Sha256: d5a36d1225da5a697b402cdd40fa6945ee0bc07f541169d84c95dc2b03c0fe6c

Contents?: true

Size: 1004 Bytes

Versions: 3

Compression:

Stored size: 1004 Bytes

Contents

require_relative 'test_helper'
require_relative 'jobs/test_job'

# Unit Test for RocketJob::Worker
class WorkerTest < Minitest::Test
  context RocketJob::Worker do
    setup do
      RocketJob::Config.instance.heartbeat_seconds = 0.1
      RocketJob::Config.instance.max_poll_seconds  = 0.1
      @worker = RocketJob::Worker.new
      @description = 'Hello World'
      @arguments   = [ 1 ]
      @job = Jobs::TestJob.new(
        description:         @description,
        arguments:           @arguments,
        destroy_on_complete: false
      )
    end

    teardown do
      @job.destroy if @job && !@job.new_record?
    end

    context '.config' do
      should 'support multiple databases' do
        assert_equal 'test_rocketjob', RocketJob::Job.collection.db.name
      end
    end

    context '#run' do
      should 'run a worker' do
        Thread.new { sleep 1; @worker.stop!}
        @worker.run
        assert_equal :stopping, @worker.state, @worker.inspect
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rocketjob-1.0.0 test/worker_test.rb
rocketjob-0.9.1 test/worker_test.rb
rocketjob-0.9.0 test/worker_test.rb