Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/solid_queue/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 ],
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) (default: fork).",
banner: "SOLID_QUEUE_SUPERVISOR_MODE"

Expand Down
46 changes: 46 additions & 0 deletions test/unit/cli_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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 option" 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 option 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 option 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