2015-12-31 18:33:35 -05:00
|
|
|
|
# frozen_string_literal: true
|
2018-12-03 16:24:37 -05:00
|
|
|
|
|
2014-12-30 15:54:58 -05:00
|
|
|
|
require_relative 'helper'
|
2012-02-12 22:53:34 -05:00
|
|
|
|
require 'sidekiq/cli'
|
|
|
|
|
|
2019-03-01 16:25:56 -05:00
|
|
|
|
describe Sidekiq::CLI do
|
|
|
|
|
describe '#parse' do
|
|
|
|
|
before do
|
|
|
|
|
Sidekiq.options = Sidekiq::DEFAULTS.dup
|
|
|
|
|
@logger = Sidekiq.logger
|
|
|
|
|
@logdev = StringIO.new
|
|
|
|
|
Sidekiq.logger = Logger.new(@logdev)
|
|
|
|
|
end
|
2014-02-01 18:04:20 -05:00
|
|
|
|
|
2019-03-01 16:25:56 -05:00
|
|
|
|
after do
|
|
|
|
|
Sidekiq.logger = @logger
|
2014-02-01 18:04:20 -05:00
|
|
|
|
end
|
2012-02-12 22:53:34 -05:00
|
|
|
|
|
2019-03-01 16:25:56 -05:00
|
|
|
|
subject { Sidekiq::CLI.new }
|
|
|
|
|
|
2019-02-07 14:42:35 -05:00
|
|
|
|
def logdev
|
|
|
|
|
@logdev ||= StringIO.new
|
|
|
|
|
end
|
2013-04-24 14:48:22 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe '#parse' do
|
|
|
|
|
describe 'options' do
|
|
|
|
|
describe 'require' do
|
|
|
|
|
it 'accepts with -r' do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb])
|
2012-02-12 22:53:34 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2013-01-06 16:01:30 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'concurrency' do
|
|
|
|
|
it 'accepts with -c' do
|
|
|
|
|
subject.parse(%w[sidekiq -c 60 -r ./test/fake_env.rb])
|
2013-04-24 14:48:22 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 60, Sidekiq.options[:concurrency]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2013-12-23 10:32:53 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when concurrency is empty and RAILS_MAX_THREADS env var is set' do
|
|
|
|
|
before do
|
|
|
|
|
ENV['RAILS_MAX_THREADS'] = '9'
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
after do
|
|
|
|
|
ENV.delete('RAILS_MAX_THREADS')
|
|
|
|
|
end
|
2013-12-23 10:32:53 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'sets concurrency from RAILS_MAX_THREADS env var' do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb])
|
2012-03-08 23:58:51 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 9, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'option overrides RAILS_MAX_THREADS env var' do
|
|
|
|
|
subject.parse(%w[sidekiq -c 60 -r ./test/fake_env.rb])
|
2012-08-15 14:46:43 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 60, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-10-25 15:40:42 -04:00
|
|
|
|
|
2020-05-07 12:00:19 -04:00
|
|
|
|
describe 'setting internal options via the config file' do
|
|
|
|
|
describe 'setting the `strict` option via the config file' do
|
|
|
|
|
it 'discards the `strict` option specified via the config file' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_with_internal_options.yml])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'queues' do
|
|
|
|
|
it 'accepts with -q' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo -r ./test/fake_env.rb])
|
2018-08-24 14:35:07 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal ['foo'], Sidekiq.options[:queues]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-03-14 13:09:46 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when weights are not present' do
|
|
|
|
|
it 'accepts queues without weights' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo -q bar -r ./test/fake_env.rb])
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal ['foo', 'bar'], Sidekiq.options[:queues]
|
|
|
|
|
end
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo -q bar -r ./test/fake_env.rb])
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when weights are present' do
|
|
|
|
|
it 'accepts queues with weights' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo,3 -q bar -r ./test/fake_env.rb])
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal ['foo', 'foo', 'foo', 'bar'], Sidekiq.options[:queues]
|
|
|
|
|
end
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'does not set strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo,3 -q bar -r ./test/fake_env.rb])
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal false, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'accepts queues with multi-word names' do
|
|
|
|
|
subject.parse(%w[sidekiq -q queue_one -q queue-two -r ./test/fake_env.rb])
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal ['queue_one', 'queue-two'], Sidekiq.options[:queues]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-12-11 06:32:22 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'accepts queues with dots in the name' do
|
|
|
|
|
subject.parse(%w[sidekiq -q foo.bar -r ./test/fake_env.rb])
|
2012-02-15 21:13:32 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal ['foo.bar'], Sidekiq.options[:queues]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-02-15 13:56:36 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when duplicate queue names' do
|
|
|
|
|
it 'raises an argument error' do
|
|
|
|
|
assert_raises(ArgumentError) { subject.parse(%w[sidekiq -q foo -q foo -r ./test/fake_env.rb]) }
|
|
|
|
|
assert_raises(ArgumentError) { subject.parse(%w[sidekiq -q foo,3 -q foo,1 -r ./test/fake_env.rb]) }
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-02 15:26:25 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when queues are empty' do
|
2020-05-05 15:57:21 -04:00
|
|
|
|
describe 'when no queues are specified via -q' do
|
|
|
|
|
it "sets 'default' queue" do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb])
|
|
|
|
|
|
|
|
|
|
assert_equal ['default'], Sidekiq.options[:queues]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when no queues are specified via the config file' do
|
|
|
|
|
it "sets 'default' queue" do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_empty.yml -r ./test/fake_env.rb])
|
2012-02-15 21:13:32 -05:00
|
|
|
|
|
2020-05-05 15:57:21 -04:00
|
|
|
|
assert_equal ['default'], Sidekiq.options[:queues]
|
|
|
|
|
end
|
2018-12-28 18:05:51 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2014-08-18 11:59:14 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'timeout' do
|
|
|
|
|
it 'accepts with -t' do
|
|
|
|
|
subject.parse(%w[sidekiq -t 30 -r ./test/fake_env.rb])
|
|
|
|
|
|
|
|
|
|
assert_equal 30, Sidekiq.options[:timeout]
|
|
|
|
|
end
|
2012-02-15 21:13:32 -05:00
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'verbose' do
|
|
|
|
|
it 'accepts with -v' do
|
|
|
|
|
subject.parse(%w[sidekiq -v -r ./test/fake_env.rb])
|
2018-12-03 16:24:37 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal Logger::DEBUG, Sidekiq.logger.level
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-02-15 21:13:32 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'config file' do
|
|
|
|
|
it 'accepts with -C' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config.yml])
|
2018-12-03 16:24:37 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal './test/config.yml', Sidekiq.options[:config_file]
|
|
|
|
|
refute Sidekiq.options[:verbose]
|
|
|
|
|
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
|
|
|
|
assert_nil Sidekiq.options[:environment]
|
|
|
|
|
assert_equal 50, Sidekiq.options[:concurrency]
|
|
|
|
|
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
|
|
|
|
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'accepts stringy keys' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_string.yml])
|
2018-12-03 16:24:37 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal './test/config_string.yml', Sidekiq.options[:config_file]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
refute Sidekiq.options[:verbose]
|
|
|
|
|
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
|
|
|
|
assert_nil Sidekiq.options[:environment]
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 50, Sidekiq.options[:concurrency]
|
|
|
|
|
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
|
|
|
|
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-11-07 01:54:31 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'accepts environment specific config' do
|
|
|
|
|
subject.parse(%w[sidekiq -e staging -C ./test/config_environment.yml])
|
2018-12-03 16:24:37 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal './test/config_environment.yml', Sidekiq.options[:config_file]
|
2018-12-03 16:24:37 -05:00
|
|
|
|
refute Sidekiq.options[:verbose]
|
|
|
|
|
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 'staging', Sidekiq.options[:environment]
|
|
|
|
|
assert_equal 50, Sidekiq.options[:concurrency]
|
|
|
|
|
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
|
|
|
|
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2012-11-07 01:54:31 -05:00
|
|
|
|
end
|
2018-12-13 11:30:29 -05:00
|
|
|
|
|
|
|
|
|
describe 'default config file' do
|
|
|
|
|
describe 'when required path is a directory' do
|
2019-01-08 12:20:59 -05:00
|
|
|
|
it 'tries config/sidekiq.yml from required diretory' do
|
2019-02-07 14:42:35 -05:00
|
|
|
|
subject.parse(%w[sidekiq -r ./test/dummy])
|
2018-12-13 11:30:29 -05:00
|
|
|
|
|
2019-01-08 12:20:59 -05:00
|
|
|
|
assert_equal './test/dummy/config/sidekiq.yml', Sidekiq.options[:config_file]
|
|
|
|
|
assert_equal 25, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when required path is a file' do
|
|
|
|
|
it 'tries config/sidekiq.yml from current diretory' do
|
|
|
|
|
Sidekiq.options[:require] = './test/dummy' # stub current dir – ./
|
|
|
|
|
|
2019-02-07 14:42:35 -05:00
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb])
|
2019-01-08 12:20:59 -05:00
|
|
|
|
|
|
|
|
|
assert_equal './test/dummy/config/sidekiq.yml', Sidekiq.options[:config_file]
|
|
|
|
|
assert_equal 25, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'without any required path' do
|
|
|
|
|
it 'tries config/sidekiq.yml from current diretory' do
|
|
|
|
|
Sidekiq.options[:require] = './test/dummy' # stub current dir – ./
|
|
|
|
|
|
2019-02-07 14:42:35 -05:00
|
|
|
|
subject.parse(%w[sidekiq])
|
2019-01-08 12:20:59 -05:00
|
|
|
|
|
|
|
|
|
assert_equal './test/dummy/config/sidekiq.yml', Sidekiq.options[:config_file]
|
2018-12-13 11:30:29 -05:00
|
|
|
|
assert_equal 25, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-11-07 01:54:31 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when config file and flags' do
|
|
|
|
|
it 'merges options' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config.yml
|
|
|
|
|
-e snoop
|
|
|
|
|
-c 100
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q often,7
|
|
|
|
|
-q seldom,3])
|
|
|
|
|
|
|
|
|
|
assert_equal './test/config.yml', Sidekiq.options[:config_file]
|
|
|
|
|
refute Sidekiq.options[:verbose]
|
|
|
|
|
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
|
|
|
|
assert_equal 'snoop', Sidekiq.options[:environment]
|
|
|
|
|
assert_equal 100, Sidekiq.options[:concurrency]
|
|
|
|
|
assert_equal 7, Sidekiq.options[:queues].count { |q| q == 'often' }
|
|
|
|
|
assert_equal 3, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
|
|
|
|
end
|
2020-05-05 16:00:48 -04:00
|
|
|
|
|
|
|
|
|
describe 'when the config file specifies queues with weights' do
|
|
|
|
|
describe 'when -q specifies queues without weights' do
|
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo -q bar])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies no queues' do
|
|
|
|
|
it 'does not set strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config.yml
|
|
|
|
|
-r ./test/fake_env.rb])
|
|
|
|
|
|
|
|
|
|
assert_equal false, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies queues with weights' do
|
|
|
|
|
it 'does not set strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo,2 -q bar,3])
|
|
|
|
|
|
|
|
|
|
assert_equal false, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when the config file specifies queues without weights' do
|
|
|
|
|
describe 'when -q specifies queues without weights' do
|
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_queues_without_weights.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo -q bar])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies no queues' do
|
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_queues_without_weights.yml
|
|
|
|
|
-r ./test/fake_env.rb])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies queues with weights' do
|
|
|
|
|
it 'does not set strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_queues_without_weights.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo,2 -q bar,3])
|
|
|
|
|
|
|
|
|
|
assert_equal false, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when the config file specifies no queues' do
|
|
|
|
|
describe 'when -q specifies queues without weights' do
|
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_empty.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo -q bar])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies no queues' do
|
|
|
|
|
it 'sets strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_empty.yml
|
|
|
|
|
-r ./test/fake_env.rb])
|
|
|
|
|
|
|
|
|
|
assert_equal true, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when -q specifies queues with weights' do
|
|
|
|
|
it 'does not set strictly ordered queues' do
|
|
|
|
|
subject.parse(%w[sidekiq -C ./test/config_empty.yml
|
|
|
|
|
-r ./test/fake_env.rb
|
|
|
|
|
-q foo,2 -q bar,3])
|
|
|
|
|
|
|
|
|
|
assert_equal false, !!Sidekiq.options[:strict]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-12-28 18:05:51 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'default config file' do
|
|
|
|
|
describe 'when required path is a directory' do
|
|
|
|
|
it 'tries config/sidekiq.yml' do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/dummy])
|
|
|
|
|
|
|
|
|
|
assert_equal 'sidekiq.yml', File.basename(Sidekiq.options[:config_file])
|
|
|
|
|
assert_equal 25, Sidekiq.options[:concurrency]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'validation' do
|
|
|
|
|
describe 'when required application path does not exist' do
|
|
|
|
|
it 'exits with status 1' do
|
|
|
|
|
exit = assert_raises(SystemExit) { subject.parse(%w[sidekiq -r /non/existent/path]) }
|
|
|
|
|
assert_equal 1, exit.status
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
end
|
2018-12-13 11:30:29 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when required path is a directory without config/application.rb' do
|
|
|
|
|
it 'exits with status 1' do
|
|
|
|
|
exit = assert_raises(SystemExit) { subject.parse(%w[sidekiq -r ./test/fixtures]) }
|
|
|
|
|
assert_equal 1, exit.status
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when config file path does not exist' do
|
|
|
|
|
it 'raises argument error' do
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb -C /non/existent/path])
|
|
|
|
|
end
|
2018-12-13 11:30:29 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-05-04 12:51:32 -04:00
|
|
|
|
|
|
|
|
|
describe 'when concurrency is not valid' do
|
|
|
|
|
describe 'when set to 0' do
|
|
|
|
|
it 'raises argument error' do
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb -c 0])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when set to a negative number' do
|
|
|
|
|
it 'raises argument error' do
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb -c -2])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when timeout is not valid' do
|
|
|
|
|
describe 'when set to 0' do
|
|
|
|
|
it 'raises argument error' do
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb -t 0])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'when set to a negative number' do
|
|
|
|
|
it 'raises argument error' do
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
|
subject.parse(%w[sidekiq -r ./test/fake_env.rb -t -2])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2012-03-08 23:58:51 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe '#run' do
|
|
|
|
|
before do
|
2020-06-19 11:39:18 -04:00
|
|
|
|
Sidekiq.options[:concurrency] = 2
|
2018-12-28 18:05:51 -05:00
|
|
|
|
Sidekiq.options[:require] = './test/fake_env.rb'
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'require workers' do
|
|
|
|
|
describe 'when path is a rails directory' do
|
|
|
|
|
before do
|
|
|
|
|
Sidekiq.options[:require] = './test/dummy'
|
|
|
|
|
subject.environment = 'test'
|
|
|
|
|
end
|
2015-07-10 15:35:02 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'requires sidekiq railtie and rails application with environment' do
|
|
|
|
|
subject.stub(:launch, nil) do
|
|
|
|
|
subject.run
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert defined?(Sidekiq::Rails)
|
|
|
|
|
assert defined?(Dummy::Application)
|
2018-12-07 11:59:42 -05:00
|
|
|
|
end
|
2016-01-29 20:12:27 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
it 'tags with the app directory name' do
|
|
|
|
|
subject.stub(:launch, nil) do
|
|
|
|
|
subject.run
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_equal 'dummy', Sidekiq.options[:tag]
|
2018-12-07 11:59:42 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when path is file' do
|
|
|
|
|
it 'requires application' do
|
|
|
|
|
subject.stub(:launch, nil) do
|
|
|
|
|
subject.run
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert $LOADED_FEATURES.any? { |x| x =~ /test\/fake_env/ }
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'when development environment and stdout tty' do
|
|
|
|
|
it 'prints banner' do
|
|
|
|
|
subject.stub(:environment, 'development') do
|
|
|
|
|
assert_output(/#{Regexp.escape(Sidekiq::CLI.banner)}/) do
|
|
|
|
|
$stdout.stub(:tty?, true) do
|
|
|
|
|
subject.stub(:launch, nil) do
|
|
|
|
|
subject.run
|
|
|
|
|
end
|
2018-12-07 11:59:42 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-11-17 20:50:01 -05:00
|
|
|
|
|
|
|
|
|
it 'prints rails info' do
|
|
|
|
|
subject.stub(:environment, 'production') do
|
|
|
|
|
subject.stub(:launch, nil) do
|
|
|
|
|
subject.run
|
|
|
|
|
end
|
|
|
|
|
assert_includes @logdev.string, "Booted Rails #{::Rails.version} application in production environment"
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2016-01-18 22:00:06 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'signal handling' do
|
|
|
|
|
%w(INT TERM).each do |sig|
|
|
|
|
|
describe sig do
|
|
|
|
|
it 'raises interrupt error' do
|
|
|
|
|
assert_raises Interrupt do
|
|
|
|
|
subject.handle_signal(sig)
|
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2016-01-18 22:00:06 -05:00
|
|
|
|
end
|
2015-07-10 15:35:02 -04:00
|
|
|
|
end
|
2016-01-01 11:58:42 -05:00
|
|
|
|
|
2019-08-02 14:07:16 -04:00
|
|
|
|
describe "TSTP" do
|
|
|
|
|
it 'quiets with a corresponding event' do
|
|
|
|
|
quiet = false
|
2016-01-01 11:58:42 -05:00
|
|
|
|
|
2019-08-02 14:07:16 -04:00
|
|
|
|
Sidekiq.on(:quiet) do
|
|
|
|
|
quiet = true
|
|
|
|
|
end
|
2016-01-01 11:58:42 -05:00
|
|
|
|
|
2019-08-02 14:07:16 -04:00
|
|
|
|
subject.launcher = Sidekiq::Launcher.new(Sidekiq.options)
|
|
|
|
|
subject.handle_signal("TSTP")
|
2016-01-18 22:00:06 -05:00
|
|
|
|
|
2019-08-02 14:07:16 -04:00
|
|
|
|
assert_match(/Got TSTP signal/, logdev.string)
|
|
|
|
|
assert_equal true, quiet
|
2016-01-18 22:00:06 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'TTIN' do
|
|
|
|
|
it 'prints backtraces for all threads in the process to the logfile' do
|
|
|
|
|
subject.handle_signal('TTIN')
|
2016-01-18 22:00:06 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_match(/Got TTIN signal/, logdev.string)
|
|
|
|
|
assert_match(/\bbacktrace\b/, logdev.string)
|
|
|
|
|
end
|
2016-01-01 11:58:42 -05:00
|
|
|
|
end
|
2015-07-10 15:35:02 -04:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
describe 'UNKNOWN' do
|
|
|
|
|
it 'logs about' do
|
|
|
|
|
# subject.parse(%w[sidekiq -r ./test/fake_env.rb])
|
|
|
|
|
subject.handle_signal('UNKNOWN')
|
2016-01-18 22:00:06 -05:00
|
|
|
|
|
2018-12-28 18:05:51 -05:00
|
|
|
|
assert_match(/Got UNKNOWN signal/, logdev.string)
|
2019-09-05 09:02:55 -04:00
|
|
|
|
assert_match(/No signal handler registered/, logdev.string)
|
2018-12-28 18:05:51 -05:00
|
|
|
|
end
|
2018-12-03 16:24:37 -05:00
|
|
|
|
end
|
2015-07-10 15:35:02 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2012-02-12 22:53:34 -05:00
|
|
|
|
end
|