2013-03-19 18:54:55 -04:00
|
|
|
|
# encoding: utf-8
|
2014-12-30 15:54:58 -05:00
|
|
|
|
require_relative 'helper'
|
2012-12-02 18:55:21 -05:00
|
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
|
class TestSidekiq < Sidekiq::Test
|
2012-12-02 18:55:21 -05:00
|
|
|
|
describe 'json processing' do
|
|
|
|
|
it 'loads json' do
|
|
|
|
|
assert_equal ({"foo" => "bar"}), Sidekiq.load_json("{\"foo\":\"bar\"}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'dumps json' do
|
|
|
|
|
assert_equal "{\"foo\":\"bar\"}", Sidekiq.dump_json({ "foo" => "bar" })
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-02-02 05:47:58 -05:00
|
|
|
|
describe "redis connection" do
|
|
|
|
|
it "returns error without creating a connection if block is not given" do
|
2013-05-12 17:25:30 -04:00
|
|
|
|
mock = Minitest::Mock.new
|
2013-02-02 05:47:58 -05:00
|
|
|
|
mock.expect :create, nil #Sidekiq::RedisConnection, create
|
|
|
|
|
assert_raises(ArgumentError) {
|
|
|
|
|
Sidekiq.redis
|
|
|
|
|
}
|
|
|
|
|
assert_raises(MockExpectationError, "create should not be called") do
|
|
|
|
|
mock.verify
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-19 18:54:55 -04:00
|
|
|
|
describe "❨╯°□°❩╯︵┻━┻" do
|
|
|
|
|
before { $stdout = StringIO.new }
|
|
|
|
|
after { $stdout = STDOUT }
|
|
|
|
|
|
|
|
|
|
it "allows angry developers to express their emotional constitution and remedies it" do
|
|
|
|
|
Sidekiq.❨╯°□°❩╯︵┻━┻
|
|
|
|
|
assert_equal "Calm down, bro\n", $stdout.string
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-03-10 23:46:19 -04:00
|
|
|
|
|
|
|
|
|
describe 'lifecycle events' do
|
|
|
|
|
it 'handles invalid input' do
|
2014-05-13 17:00:20 -04:00
|
|
|
|
Sidekiq.options[:lifecycle_events][:startup].clear
|
|
|
|
|
|
2014-03-10 23:46:19 -04:00
|
|
|
|
e = assert_raises ArgumentError do
|
2014-03-12 00:21:21 -04:00
|
|
|
|
Sidekiq.on(:startp)
|
2014-03-10 23:46:19 -04:00
|
|
|
|
end
|
2014-03-19 20:41:11 -04:00
|
|
|
|
assert_match(/Invalid event name/, e.message)
|
2014-03-10 23:46:19 -04:00
|
|
|
|
e = assert_raises ArgumentError do
|
2014-03-12 00:21:21 -04:00
|
|
|
|
Sidekiq.on('startup')
|
2014-03-10 23:46:19 -04:00
|
|
|
|
end
|
2014-03-19 20:41:11 -04:00
|
|
|
|
assert_match(/Symbols only/, e.message)
|
2014-03-12 00:21:21 -04:00
|
|
|
|
Sidekiq.on(:startup) do
|
2014-03-10 23:51:10 -04:00
|
|
|
|
1 + 1
|
|
|
|
|
end
|
|
|
|
|
|
2014-03-12 00:21:21 -04:00
|
|
|
|
assert_equal 2, Sidekiq.options[:lifecycle_events][:startup].first.call
|
2014-03-10 23:46:19 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-09 12:08:58 -05:00
|
|
|
|
|
|
|
|
|
describe 'default_worker_options' do
|
|
|
|
|
before do
|
|
|
|
|
@old_options = Sidekiq.default_worker_options
|
|
|
|
|
end
|
|
|
|
|
after { Sidekiq.default_worker_options = @old_options }
|
|
|
|
|
|
|
|
|
|
it 'stringify keys' do
|
|
|
|
|
Sidekiq.default_worker_options = { queue: 'cat'}
|
|
|
|
|
assert_equal 'cat', Sidekiq.default_worker_options['queue']
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-09-22 17:38:33 -04:00
|
|
|
|
end
|