Sha256: 01f685defaf746fde2bda13c9eb520820069b862f2336cfbee18128cba539570

Contents?: true

Size: 1.99 KB

Versions: 21

Compression:

Stored size: 1.99 KB

Contents

require_relative 'test_helper'

# Unit Test for RocketJob::Job
class JobTest < Minitest::Test

  class SimpleJob < RocketJob::Job
    def perform
    end
  end

  describe RocketJob::Job do
    before do
      @description = 'Hello World'
      @job         = SimpleJob.new(description: @description)
      @job2        = SimpleJob.new(description: @description, priority: 52)
    end

    after do
      @job.destroy if @job && !@job.new_record?
      @job2.destroy if @job2 && !@job2.new_record?
    end

    describe '#status' do
      it 'return status for a queued job' do
        assert_equal true, @job.queued?
        h = @job.status
        assert_equal :queued, h['state']
        assert_equal @description, h['description']
      end

      it 'return status for a failed job' do
        @job.start!
        @job.fail!('worker:1234', 'oh no')
        assert_equal true, @job.failed?
        h = @job.status
        assert_equal :failed, h['state']
        assert_equal @description, h['description']
        assert_equal 'RocketJob::JobException', h['exception']['class_name'], h
        assert_equal 'oh no', h['exception']['message'], h
      end
    end

    describe '.requeue_dead_server' do
      it 'requeue jobs from dead workers' do
        assert_equal 52, @job2.priority
        worker_name      = 'server:12345'
        @job.worker_name = worker_name
        @job.start!
        assert @job.running?, @job.state

        worker_name2      = 'server:76467'
        @job2.worker_name = worker_name2
        @job2.start!
        assert_equal true, @job2.valid?
        assert @job2.running?, @job2.state
        @job2.save!

        RocketJob::Job.requeue_dead_server(worker_name)
        @job.reload

        assert @job.queued?
        assert_nil @job.worker_name

        assert_equal worker_name2, @job2.worker_name
        @job2.reload
        assert_equal worker_name2, @job2.worker_name
        assert @job2.running?, @job2.state
        assert_equal worker_name2, @job2.worker_name
      end
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rocketjob-3.4.3 test/job_test.rb
rocketjob-3.4.2 test/job_test.rb
rocketjob-3.4.1 test/job_test.rb
rocketjob-3.4.0 test/job_test.rb
rocketjob-3.3.4 test/job_test.rb
rocketjob-3.3.3 test/job_test.rb
rocketjob-3.3.2 test/job_test.rb
rocketjob-3.3.1 test/job_test.rb
rocketjob-3.3.0 test/job_test.rb
rocketjob-3.2.1 test/job_test.rb
rocketjob-3.2.0 test/job_test.rb
rocketjob-3.1.0 test/job_test.rb
rocketjob-3.0.5 test/job_test.rb
rocketjob-3.0.4 test/job_test.rb
rocketjob-3.0.3 test/job_test.rb
rocketjob-3.0.2 test/job_test.rb
rocketjob-3.0.1 test/job_test.rb
rocketjob-3.0.0 test/job_test.rb
rocketjob-3.0.0.rc5 test/job_test.rb
rocketjob-3.0.0.rc4 test/job_test.rb