2014-08-18 03:19:41 -04:00
|
|
|
require 'helper'
|
|
|
|
require 'jobs/logging_job'
|
|
|
|
require 'active_support/core_ext/numeric/time'
|
|
|
|
|
|
|
|
class QueuingTest < ActiveSupport::TestCase
|
2014-10-22 09:33:10 -04:00
|
|
|
test 'should run jobs enqueued on a listening queue' do
|
2014-08-18 03:19:41 -04:00
|
|
|
TestJob.perform_later @id
|
|
|
|
wait_for_jobs_to_finish_for(5.seconds)
|
|
|
|
assert job_executed
|
|
|
|
end
|
|
|
|
|
2014-10-22 09:33:10 -04:00
|
|
|
test 'should not run jobs queued on a non-listening queue' do
|
2014-10-10 02:53:22 -04:00
|
|
|
skip if adapter_is?(:inline) || adapter_is?(:sucker_punch)
|
|
|
|
old_queue = TestJob.queue_name
|
|
|
|
|
2014-08-18 03:19:41 -04:00
|
|
|
begin
|
|
|
|
TestJob.queue_as :some_other_queue
|
|
|
|
TestJob.perform_later @id
|
|
|
|
wait_for_jobs_to_finish_for(2.seconds)
|
|
|
|
assert_not job_executed
|
|
|
|
ensure
|
|
|
|
TestJob.queue_name = old_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not run job enqueued in the future' do
|
|
|
|
begin
|
|
|
|
TestJob.set(wait: 10.minutes).perform_later @id
|
|
|
|
wait_for_jobs_to_finish_for(5.seconds)
|
|
|
|
assert_not job_executed
|
|
|
|
rescue NotImplementedError
|
|
|
|
skip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should run job enqueued in the future at the specified time' do
|
|
|
|
begin
|
|
|
|
TestJob.set(wait: 3.seconds).perform_later @id
|
|
|
|
wait_for_jobs_to_finish_for(2.seconds)
|
|
|
|
assert_not job_executed
|
|
|
|
wait_for_jobs_to_finish_for(10.seconds)
|
|
|
|
assert job_executed
|
|
|
|
rescue NotImplementedError
|
|
|
|
skip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|