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