Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/solid_queue/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Cli < Thor
desc: "Path to config file (default: #{Configuration::DEFAULT_CONFIG_FILE_PATH}).",
banner: "SOLID_QUEUE_CONFIG"

class_option :mode, type: :string, default: "fork", enum: %w[ fork async ],
desc: "Whether to fork processes for workers and dispatchers (fork) or to run these in the same process as the supervisor (async) (default: fork).",
class_option :mode, type: :string, enum: %w[ fork async ],
desc: "Whether to fork processes for workers and dispatchers (fork) or to run these in the same process as the supervisor (async). Can also be set via SOLID_QUEUE_SUPERVISOR_MODE env var (default: fork).",
banner: "SOLID_QUEUE_SUPERVISOR_MODE"

class_option :recurring_schedule_file, type: :string,
Expand Down
41 changes: 41 additions & 0 deletions test/unit/cli_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "test_helper"
require "solid_queue/cli"

class CliTest < ActiveSupport::TestCase
test "mode defaults to fork when no env var or argument" do
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => nil) do
config = configuration_from_cli
assert config.mode.fork?
end
end

test "mode respects SOLID_QUEUE_SUPERVISOR_MODE env var" do
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => "async") do
config = configuration_from_cli
assert config.mode.async?
end
end

test "mode argument overrides env var" do
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => "async") do
config = configuration_from_cli(mode: "fork")
assert config.mode.fork?
end
end

test "mode argument works without env var" do
with_env("SOLID_QUEUE_SUPERVISOR_MODE" => nil) do
config = configuration_from_cli(mode: "async")
assert config.mode.async?
end
end

private
def configuration_from_cli(**cli_options)
cli = SolidQueue::Cli.new([], cli_options)
options = cli.options.symbolize_keys.compact
SolidQueue::Configuration.new(**options)
end
end
Loading