New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix #3044] Set conditional config defaults after CLI options are parsed and config files are loaded #3297
Open
joshuay03
wants to merge
1
commit into
puma:master
Choose a base branch
from
joshuay03:set-conditional-config-defaults-after-cli-options-parse
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−20
Open
[Fix #3044] Set conditional config defaults after CLI options are parsed and config files are loaded #3297
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/config/worker_shutdown_timeout_2.rb → test/config/worker_respawn.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
worker_shutdown_timeout 2 | ||
preload_app! false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workers 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workers 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,7 +352,6 @@ def test_environment_app_env | |
ENV['APP_ENV'] = 'test' | ||
|
||
cli = Puma::CLI.new [] | ||
cli.send(:setup_options) | ||
|
||
assert_equal 'test', cli.instance_variable_get(:@conf).environment | ||
ensure | ||
|
@@ -364,7 +363,6 @@ def test_environment_rack_env | |
ENV['RACK_ENV'] = @environment | ||
|
||
cli = Puma::CLI.new [] | ||
cli.send(:setup_options) | ||
|
||
assert_equal @environment, cli.instance_variable_get(:@conf).environment | ||
end | ||
|
@@ -374,7 +372,6 @@ def test_environment_rails_env | |
ENV['RAILS_ENV'] = @environment | ||
|
||
cli = Puma::CLI.new [] | ||
cli.send(:setup_options) | ||
|
||
assert_equal @environment, cli.instance_variable_get(:@conf).environment | ||
ensure | ||
|
@@ -383,7 +380,6 @@ def test_environment_rails_env | |
|
||
def test_silent | ||
cli = Puma::CLI.new ['--silent'] | ||
cli.send(:setup_options) | ||
|
||
log_writer = cli.instance_variable_get(:@log_writer) | ||
|
||
|
@@ -396,9 +392,26 @@ def test_plugins | |
assert_empty Puma::Plugins.instance_variable_get(:@plugins) | ||
|
||
cli = Puma::CLI.new ['--plugin', 'tmp_restart', '--plugin', 'systemd'] | ||
cli.send(:setup_options) | ||
|
||
assert Puma::Plugins.find("tmp_restart") | ||
assert Puma::Plugins.find("systemd") | ||
end | ||
|
||
def test_config_does_not_preload_app_with_workers | ||
skip_unless :fork | ||
|
||
cli = Puma::CLI.new ['-w 0'] | ||
config = Puma.cli_config | ||
|
||
assert_equal false, config.options[:preload_app] | ||
end | ||
|
||
def test_config_preloads_app_with_workers | ||
skip_unless :fork | ||
|
||
cli = Puma::CLI.new ['-w 2'] | ||
config = Puma.cli_config | ||
|
||
assert_equal true, config.options[:preload_app] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,6 +576,34 @@ def test_http_content_length_limit | |
assert_equal 10000, conf.final_options[:http_content_length_limit] | ||
end | ||
|
||
def test_config_does_not_preload_app_if_not_using_workers | ||
conf = Puma::Configuration.new({ workers: 0 }) | ||
|
||
assert_equal false, conf.options.default_options[:preload_app] | ||
end | ||
|
||
def test_config_preloads_app_if_using_workers | ||
conf = Puma::Configuration.new({ workers: 2 }) | ||
preload = Puma.forkable? | ||
|
||
assert_equal preload, conf.options.default_options[:preload_app] | ||
end | ||
|
||
def test_config_file_does_not_preload_app_if_not_using_workers | ||
conf = Puma::Configuration.new { |c| c.load 'test/config/workers_0.rb' } | ||
conf.load | ||
|
||
assert_equal false, conf.options.default_options[:preload_app] | ||
end | ||
|
||
def test_config_file_preloads_app_if_using_workers | ||
conf = Puma::Configuration.new { |c| c.load 'test/config/workers_2.rb' } | ||
conf.load | ||
preload = Puma.forkable? | ||
|
||
assert_equal preload, conf.options.default_options[:preload_app] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
|
||
private | ||
|
||
def assert_run_hooks(hook_name, options = {}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are unnecessary, options are set up when initialised.