2013-03-11 08:24:11 -04:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestSidetiq < Sidetiq::TestCase
|
|
|
|
def test_schedules
|
2013-03-11 13:11:37 -04:00
|
|
|
schedules = Sidetiq.schedules
|
|
|
|
|
2013-09-17 11:48:41 -04:00
|
|
|
assert_includes schedules, ScheduledWorker.schedule
|
|
|
|
assert_includes schedules, BackfillWorker.schedule
|
2013-03-11 13:11:37 -04:00
|
|
|
|
2013-09-17 11:48:41 -04:00
|
|
|
assert_kind_of Sidetiq::Schedule, ScheduledWorker.schedule
|
|
|
|
assert_kind_of Sidetiq::Schedule, BackfillWorker.schedule
|
2013-03-11 08:24:11 -04:00
|
|
|
end
|
2013-03-11 08:24:42 -04:00
|
|
|
|
|
|
|
def test_workers
|
2013-03-11 13:11:37 -04:00
|
|
|
workers = Sidetiq.workers
|
|
|
|
|
|
|
|
assert_includes workers, ScheduledWorker
|
|
|
|
assert_includes workers, BackfillWorker
|
2013-03-11 08:24:42 -04:00
|
|
|
end
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
def test_scheduled
|
|
|
|
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
|
2013-07-12 05:17:07 -04:00
|
|
|
hash = SimpleWorker.jobs.first
|
|
|
|
Sidekiq::Client.push_old(hash.merge("at" => hash["enqueued_at"]))
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
scheduled = Sidetiq.scheduled
|
|
|
|
|
|
|
|
assert_kind_of Array, scheduled
|
|
|
|
assert_kind_of Sidekiq::SortedEntry, scheduled.first
|
|
|
|
assert_equal 1, scheduled.length
|
|
|
|
end
|
|
|
|
|
2013-03-11 09:01:37 -04:00
|
|
|
def test_scheduled_on_empty_set
|
|
|
|
assert_equal 0, Sidetiq.scheduled.length
|
|
|
|
end
|
|
|
|
|
2013-03-11 08:25:07 -04:00
|
|
|
def test_scheduled_given_arguments
|
|
|
|
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
|
2013-07-12 05:17:07 -04:00
|
|
|
hash = SimpleWorker.jobs.first
|
|
|
|
Sidekiq::Client.push_old(hash.merge("at" => hash["enqueued_at"]))
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
assert_equal 1, Sidetiq.scheduled(SimpleWorker).length
|
|
|
|
assert_equal 0, Sidetiq.scheduled(ScheduledWorker).length
|
|
|
|
|
|
|
|
assert_equal 1, Sidetiq.scheduled("SimpleWorker").length
|
|
|
|
assert_equal 0, Sidetiq.scheduled("ScheduledWorker").length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_scheduled_yields_each_job
|
|
|
|
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
|
2013-07-12 05:17:07 -04:00
|
|
|
hash = SimpleWorker.jobs.first
|
|
|
|
Sidekiq::Client.push_old(hash.merge("at" => hash["enqueued_at"]))
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
ScheduledWorker.perform_at(Time.local(2011, 1, 1, 1))
|
2013-07-12 05:17:07 -04:00
|
|
|
hash = ScheduledWorker.jobs.first
|
|
|
|
Sidekiq::Client.push_old(hash.merge("at" => hash["enqueued_at"]))
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.scheduled { |job| jobs << job }
|
|
|
|
assert_equal 2, jobs.length
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.scheduled(SimpleWorker) { |job| jobs << job }
|
|
|
|
assert_equal 1, jobs.length
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.scheduled("ScheduledWorker") { |job| jobs << job }
|
|
|
|
assert_equal 1, jobs.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_scheduled_with_invalid_class
|
|
|
|
assert_raises(NameError) do
|
|
|
|
Sidetiq.scheduled("Foobar")
|
|
|
|
end
|
|
|
|
end
|
2013-03-11 09:01:37 -04:00
|
|
|
|
|
|
|
def test_retries
|
|
|
|
add_retry('SimpleWorker', 'foo')
|
|
|
|
add_retry('ScheduledWorker', 'bar')
|
|
|
|
|
|
|
|
retries = Sidetiq.retries
|
|
|
|
|
|
|
|
assert_kind_of Array, retries
|
|
|
|
assert_kind_of Sidekiq::SortedEntry, retries[0]
|
|
|
|
assert_kind_of Sidekiq::SortedEntry, retries[1]
|
|
|
|
assert_equal 2, retries.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_retries_on_empty_set
|
|
|
|
assert_equal 0, Sidetiq.retries.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_retries_given_arguments
|
|
|
|
add_retry('SimpleWorker', 'foo')
|
|
|
|
|
|
|
|
assert_equal 1, Sidetiq.retries(SimpleWorker).length
|
|
|
|
assert_equal 0, Sidetiq.retries(ScheduledWorker).length
|
|
|
|
|
|
|
|
assert_equal 1, Sidetiq.retries("SimpleWorker").length
|
|
|
|
assert_equal 0, Sidetiq.retries("ScheduledWorker").length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_retries_yields_each_job
|
|
|
|
add_retry('SimpleWorker', 'foo')
|
|
|
|
add_retry('ScheduledWorker', 'foo')
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.retries { |job| jobs << job }
|
|
|
|
assert_equal 2, jobs.length
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.retries(SimpleWorker) { |job| jobs << job }
|
|
|
|
assert_equal 1, jobs.length
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
Sidetiq.retries("ScheduledWorker") { |job| jobs << job }
|
|
|
|
assert_equal 1, jobs.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_retries_with_invalid_class
|
|
|
|
assert_raises(NameError) do
|
|
|
|
Sidetiq.retries("Foobar")
|
|
|
|
end
|
|
|
|
end
|
2013-03-11 08:24:11 -04:00
|
|
|
end
|
|
|
|
|