Skip to content

Commit 97a3a54

Browse files
lovro-bikicrosa
authored andcommitted
Remove default value for 'mode' in CLI options
Setting a default value will override the defaults in Configuration, which reads from the SOLID_QUEUE_SUPERVISOR_MODE environment variable, effectively making it useless
1 parent 8d90eab commit 97a3a54

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

lib/solid_queue/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Cli < Thor
88
desc: "Path to config file (default: #{Configuration::DEFAULT_CONFIG_FILE_PATH}).",
99
banner: "SOLID_QUEUE_CONFIG"
1010

11-
class_option :mode, type: :string, default: "fork", enum: %w[ fork async ],
11+
class_option :mode, type: :string, enum: %w[ fork async ],
1212
desc: "Whether to fork processes for workers and dispatchers (fork) or to run these in the same process as the supervisor (async) (default: fork).",
1313
banner: "SOLID_QUEUE_SUPERVISOR_MODE"
1414

test/unit/cli_test.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "solid_queue/cli"
5+
6+
class CliTest < ActiveSupport::TestCase
7+
test "mode defaults to fork when no env var or option" do
8+
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => nil) do
9+
config = configuration_from_cli
10+
11+
assert config.mode.fork?
12+
end
13+
end
14+
15+
test "mode respects SOLID_QUEUE_SUPERVISOR_MODE env var" do
16+
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => "async") do
17+
config = configuration_from_cli
18+
19+
assert config.mode.async?
20+
end
21+
end
22+
23+
test "mode option overrides env var" do
24+
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => "async") do
25+
config = configuration_from_cli(mode: "fork")
26+
27+
assert config.mode.fork?
28+
end
29+
end
30+
31+
test "mode option works without env var" do
32+
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => nil) do
33+
config = configuration_from_cli(mode: "async")
34+
35+
assert config.mode.async?
36+
end
37+
end
38+
39+
private
40+
def configuration_from_cli(**cli_options)
41+
cli = SolidQueue::Cli.new([], cli_options)
42+
options = cli.options.symbolize_keys.compact
43+
44+
SolidQueue::Configuration.new(**options)
45+
end
46+
end

0 commit comments

Comments
 (0)