2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
require "helper"
|
|
|
|
require "jobs/hello_job"
|
2015-03-18 05:48:26 -04:00
|
|
|
|
|
|
|
class QueuePriorityTest < ActiveSupport::TestCase
|
2016-08-06 12:41:18 -04:00
|
|
|
test "priority unset by default" do
|
2016-12-24 12:29:52 -05:00
|
|
|
assert_nil HelloJob.priority
|
2015-03-18 05:48:26 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
test "uses given priority" do
|
2015-03-18 05:48:26 -04:00
|
|
|
original_priority = HelloJob.priority
|
|
|
|
|
|
|
|
begin
|
|
|
|
HelloJob.queue_with_priority 90
|
|
|
|
assert_equal 90, HelloJob.new.priority
|
|
|
|
ensure
|
|
|
|
HelloJob.priority = original_priority
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
test "evals block given to priority to determine priority" do
|
2015-03-18 05:48:26 -04:00
|
|
|
original_priority = HelloJob.priority
|
|
|
|
|
|
|
|
begin
|
|
|
|
HelloJob.queue_with_priority { 25 }
|
|
|
|
assert_equal 25, HelloJob.new.priority
|
|
|
|
ensure
|
|
|
|
HelloJob.priority = original_priority
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
test "can use arguments to determine priority in priority block" do
|
2015-03-18 05:48:26 -04:00
|
|
|
original_priority = HelloJob.priority
|
|
|
|
|
|
|
|
begin
|
2017-01-05 03:20:57 -05:00
|
|
|
HelloJob.queue_with_priority { arguments.first == "1" ? 99 : 11 }
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_equal 99, HelloJob.new("1").priority
|
|
|
|
assert_equal 11, HelloJob.new("3").priority
|
2015-03-18 05:48:26 -04:00
|
|
|
ensure
|
|
|
|
HelloJob.priority = original_priority
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
test "uses priority passed to #set" do
|
2015-03-18 05:48:26 -04:00
|
|
|
job = HelloJob.set(priority: 123).perform_later
|
|
|
|
assert_equal 123, job.priority
|
|
|
|
end
|
|
|
|
end
|