2013-03-11 08:24:11 -04:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestSidetiq < Sidetiq::TestCase
|
|
|
|
def test_schedules
|
|
|
|
assert_equal Sidetiq.schedules, Sidetiq::Clock.schedules
|
|
|
|
assert_equal [ScheduledWorker], Sidetiq.schedules.keys
|
|
|
|
assert_kind_of Sidetiq::Schedule, Sidetiq.schedules[ScheduledWorker]
|
|
|
|
end
|
2013-03-11 08:24:42 -04:00
|
|
|
|
|
|
|
def test_workers
|
|
|
|
assert_equal [ScheduledWorker], Sidetiq.workers
|
|
|
|
end
|
2013-03-11 08:25:07 -04:00
|
|
|
|
|
|
|
def test_scheduled
|
|
|
|
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
|
|
|
|
SimpleWorker.client_push_old(SimpleWorker.jobs.first)
|
|
|
|
|
|
|
|
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))
|
|
|
|
SimpleWorker.client_push_old(SimpleWorker.jobs.first)
|
|
|
|
|
|
|
|
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))
|
|
|
|
SimpleWorker.client_push_old(SimpleWorker.jobs.first)
|
|
|
|
|
|
|
|
ScheduledWorker.perform_at(Time.local(2011, 1, 1, 1))
|
|
|
|
ScheduledWorker.client_push_old(ScheduledWorker.jobs.first)
|
|
|
|
|
|
|
|
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
|
|
|
|
|