1
0
Fork 0
mirror of https://github.com/endofunky/sidetiq.git synced 2022-11-09 13:53:30 -05:00
endofunky--sidetiq/test/test_sidetiq.rb
Simon Fröhler 7bec408416 Makes Sidekiq compatible to Sidekiq 3.5.0 and Celluloid 0.17
Fixes "uninitialized constant Celluloid::SupervisionGroup" error on sidekiq start:

* require 'celluloid' instead of 'celluloid/current' in lib/sidetiq.rb
* Supervisor inherits from Celluloid::Supervision::Container instead
  of Celluloid::SupervisionGroup and uses new supervise method signature

More details about the changes in Celluloid can be found here:
https://github.com/celluloid/celluloid/wiki/DEPRECATION-WARNING

Fixes tests to work with Sidekiq 3.5.0:

* Use created_at instead of enqueued_at it the tests:
  > Set a created_at attribute when jobs are created, set enqueued_at only
    when they go into a queue. Fixes invalid latency calculations with
    scheduled jobs. [#2373, mrsimo]

  https://github.com/mperham/sidekiq/blob/master/Changes.md#340

* Set ENV['RACK_ENV'] = 'test' in test/helper.rb to fix tests to fix tests
  to work with Sidekiq 3.4.2 update:
  > Fix CSRF vulnerability in Web UI, thanks to Egor Homakov for reporting. [#2422]

  https://github.com/mperham/sidekiq/blob/master/Changes.md#342
  https://github.com/mperham/sidekiq/pull/2422/files

fixes #140
2015-09-08 15:45:17 +02:00

128 lines
3.4 KiB
Ruby

require_relative 'helper'
class TestSidetiq < Sidetiq::TestCase
def test_schedules
schedules = Sidetiq.schedules
assert_includes schedules, ScheduledWorker.schedule
assert_includes schedules, BackfillWorker.schedule
assert_kind_of Sidetiq::Schedule, ScheduledWorker.schedule
assert_kind_of Sidetiq::Schedule, BackfillWorker.schedule
end
def test_workers
workers = Sidetiq.workers
assert_includes workers, ScheduledWorker
assert_includes workers, BackfillWorker
end
def test_scheduled
client = Sidekiq::Client.new
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
hash = SimpleWorker.jobs.first
client.push_old(hash.merge("at" => hash["created_at"]))
scheduled = Sidetiq.scheduled
assert_kind_of Array, scheduled
assert_kind_of Sidekiq::SortedEntry, scheduled.first
assert_equal 1, scheduled.length
end
def test_scheduled_on_empty_set
assert_equal 0, Sidetiq.scheduled.length
end
def test_scheduled_given_arguments
client = Sidekiq::Client.new
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
hash = SimpleWorker.jobs.first
client.push_old(hash.merge("at" => hash["created_at"]))
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
client = Sidekiq::Client.new
SimpleWorker.perform_at(Time.local(2011, 1, 1, 1))
hash = SimpleWorker.jobs.first
client.push_old(hash.merge("at" => hash["created_at"]))
ScheduledWorker.perform_at(Time.local(2011, 1, 1, 1))
hash = ScheduledWorker.jobs.first
client.push_old(hash.merge("at" => hash["created_at"]))
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
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
end