test/job_test.rb in rocketjob-0.8.0 vs test/job_test.rb in rocketjob-0.9.0
- old
+ new
@@ -3,12 +3,12 @@
# Unit Test for RocketJob::Job
class JobTest < Minitest::Test
context RocketJob::Job do
setup do
- @server = RocketJob::Server.new
- @server.started
+ @worker = RocketJob::Worker.new
+ @worker.started
@description = 'Hello World'
@arguments = [ 1 ]
@job = Jobs::TestJob.new(
description: @description,
arguments: @arguments,
@@ -44,11 +44,11 @@
end
context '#save!' do
should 'save a blank job' do
@job.save!
- assert_nil @job.server_name
+ assert_nil @job.worker_name
assert_nil @job.completed_at
assert @job.created_at
assert_equal @description, @job.description
assert_equal false, @job.destroy_on_complete
assert_nil @job.expires_at
@@ -64,12 +64,12 @@
context '#status' do
should '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]
+ assert_equal :queued, h['state']
+ assert_equal @description, h['description']
end
should 'return status for a failed job' do
@job.build_exception(
class_name: 'Test',
@@ -77,38 +77,38 @@
)
@job.start!
@job.fail!
assert_equal true, @job.failed?
h = @job.status
- assert_equal :failed, h[:state]
- assert_equal @description, h[:description]
- assert_equal 'Test', h[:exception][:class_name], h
- assert_equal 'hello world', h[:exception][:message], h
+ assert_equal :failed, h['state']
+ assert_equal @description, h['description']
+ assert_equal 'Test', h['exception']['class_name'], h
+ assert_equal 'hello world', h['exception']['message'], h
end
end
context '#work' do
should 'call default perform method' do
@job.start!
- assert_equal false, @job.work(@server)
+ assert_equal false, @job.work(@worker)
assert_equal true, @job.completed?, @job.state
assert_equal 2, Jobs::TestJob.result
end
should 'call specific method' do
@job.perform_method = :sum
@job.arguments = [ 23, 45 ]
@job.start!
- assert_equal false, @job.work(@server)
+ assert_equal false, @job.work(@worker)
assert_equal true, @job.completed?
assert_equal 68, Jobs::TestJob.result
end
should 'destroy on complete' do
@job.destroy_on_complete = true
@job.start!
- assert_equal false, @job.work(@server)
+ assert_equal false, @job.work(@worker)
assert_equal nil, RocketJob::Job.find_by_id(@job.id)
end
should 'silence logging when log_level is set' do
@job.destroy_on_complete = true
@@ -116,11 +116,11 @@
@job.perform_method = :noisy_logger
@job.arguments = []
@job.start!
logged = false
Jobs::TestJob.logger.stub(:log_internal, -> level, index, message, payload, exception { logged = true if message.include?('some very noisy logging')}) do
- assert_equal false, @job.work(@server), @job.inspect
+ assert_equal false, @job.work(@worker), @job.inspect
end
assert_equal false, logged
end
should 'raise logging when log_level is set' do
@@ -131,22 +131,22 @@
@job.start!
logged = false
# Raise global log level to :info
SemanticLogger.stub(:default_level_index, 3) do
Jobs::TestJob.logger.stub(:log_internal, -> { logged = true }) do
- assert_equal false, @job.work(@server)
+ assert_equal false, @job.work(@worker)
end
end
assert_equal false, logged
end
should 'call before and after' do
named_parameters = { 'counter' => 23 }
@job.perform_method = :event
@job.arguments = [ named_parameters ]
@job.start!
- assert_equal false, @job.work(@server), @job.inspect
+ assert_equal false, @job.work(@worker), @job.inspect
assert_equal true, @job.completed?
assert_equal named_parameters.merge('before_event' => true, 'after_event' => true), @job.arguments.first
end
end
@@ -155,36 +155,36 @@
setup do
RocketJob::Job.destroy_all
end
should 'return nil when no jobs available' do
- assert_equal nil, RocketJob::Job.next_job(@server.name)
+ assert_equal nil, RocketJob::Job.next_job(@worker.name)
end
should 'return the first job' do
@job.save!
- assert job = RocketJob::Job.next_job(@server.name), "Failed to find job"
+ assert job = RocketJob::Job.next_job(@worker.name), "Failed to find job"
assert_equal @job.id, job.id
end
should 'Ignore future dated jobs' do
@job.run_at = Time.now + 1.hour
@job.save!
- assert_equal nil, RocketJob::Job.next_job(@server.name)
+ assert_equal nil, RocketJob::Job.next_job(@worker.name)
end
should 'Process future dated jobs when time is now' do
@job.run_at = Time.now
@job.save!
- assert job = RocketJob::Job.next_job(@server.name), "Failed to find future job"
+ assert job = RocketJob::Job.next_job(@worker.name), "Failed to find future job"
assert_equal @job.id, job.id
end
should 'Skip expired jobs' do
count = RocketJob::Job.count
@job.expires_at = Time.now - 100
@job.save!
- assert_equal nil, RocketJob::Job.next_job(@server.name)
+ assert_equal nil, RocketJob::Job.next_job(@worker.name)
assert_equal count, RocketJob::Job.count
end
end
end