Skip to content

Commit

Permalink
ITS THE FINAL COUNTDOWWNNNNN.....(yeah, Ill rebase)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalevin committed Apr 20, 2020
1 parent b2dad7b commit e552e6c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 50 deletions.
7 changes: 2 additions & 5 deletions lib/puma/configuration.rb
Expand Up @@ -137,10 +137,9 @@ def initialize(user_options={}, default_options = {}, &block)
@file_dsl = DSL.new(@options.file_options, self)
@default_dsl = DSL.new(@options.default_options, self)

workers_supported = !(Puma.jruby? || Puma.windows?)

if !@options[:prune_bundler]
default_options[:preload_app] = (@options[:workers] > 1) && workers_supported
default_options[:preload_app] = (@options[:workers] > 1) && ::Process.respond_to?(:fork)
end

if block
Expand Down Expand Up @@ -174,8 +173,7 @@ def flatten!
end

def default_max_threads
return 5 if Puma.mri?
16
Puma.mri? ? 5 : 16
end

def puma_default_options
Expand All @@ -186,7 +184,6 @@ def puma_default_options
:debug => false,
:binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"],
:workers => Integer(ENV['WEB_CONCURRENCY'] || 0),
:daemon => false,
:mode => :http,
:worker_timeout => DefaultWorkerTimeout,
:worker_boot_timeout => DefaultWorkerTimeout,
Expand Down
105 changes: 60 additions & 45 deletions test/test_config.rb
Expand Up @@ -6,6 +6,7 @@
require "puma/configuration"
require 'puma/events'


class TestConfigFile < TestConfigFileBase
parallelize_me!

Expand All @@ -15,51 +16,6 @@ def test_default_max_threads
assert_equal max_threads, Puma::Configuration.new.default_max_threads
end

def test_config_loads_correct_min_threads
conf = Puma::Configuration.new
assert_equal 0, conf.options.default_options[:min_threads]

ENV['MIN_THREADS'] = '7'
conf = Puma::Configuration.new
assert_equal 7, conf.options.default_options[:min_threads]

ENV['PUMA_MIN_THREADS'] = '8'
conf = Puma::Configuration.new
assert_equal 8, conf.options.default_options[:min_threads]
end

def test_config_loads_correct_max_threads
conf = Puma::Configuration.new
assert_equal conf.default_max_threads, conf.options.default_options[:max_threads]

ENV['MAX_THREADS'] = '7'
conf = Puma::Configuration.new
assert_equal 7, conf.options.default_options[:max_threads]

ENV['PUMA_MAX_THREADS'] = '8'
conf = Puma::Configuration.new
assert_equal 8, conf.options.default_options[:max_threads]
end

def test_config_loads_correct_workers
conf = Puma::Configuration.new
assert_equal 0, conf.options.default_options[:workers]

ENV['WEB_CONCURRENCY'] = '8'
conf = Puma::Configuration.new
assert_equal 8, conf.options.default_options[:workers]
end

def test_config_preloads_app_if_using_workers
ENV['WEB_CONCURRENCY'] = '0'
conf = Puma::Configuration.new
assert_equal false, conf.options.default_options[:preload_app]

ENV['WEB_CONCURRENCY'] = '2'
preload = Puma::Plugin.new.workers_supported?
conf = Puma::Configuration.new
assert_equal preload, conf.options.default_options[:preload_app]
end

def test_app_from_rackup
conf = Puma::Configuration.new do |c|
Expand Down Expand Up @@ -327,6 +283,65 @@ def test_double_bind_port
end
end

class TestConfigEnvVariables < TestConfigFileBase
def test_config_loads_correct_min_threads
conf = Puma::Configuration.new
assert_equal 0, conf.options.default_options[:min_threads]

with_env("MIN_THREADS" => "7") do
conf = Puma::Configuration.new
assert_equal 7, conf.options.default_options[:min_threads]
end

with_env("PUMA_MIN_THREADS" => "8") do
conf = Puma::Configuration.new
assert_equal 8, conf.options.default_options[:min_threads]
end
end

def test_config_loads_correct_max_threads
conf = Puma::Configuration.new
assert_equal conf.default_max_threads, conf.options.default_options[:max_threads]

with_env("MAX_THREADS" => "7") do
conf = Puma::Configuration.new
assert_equal 7, conf.options.default_options[:max_threads]
end

with_env("MAX_THREADS" => "8") do

This comment has been minimized.

Copy link
@ukolovda

ukolovda Apr 20, 2020

Should we use PUMA_PAX_THREADS instead MAX_THREADS on line 311?

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 20, 2020

Author Contributor

Yep, thanks.

conf = Puma::Configuration.new
assert_equal 8, conf.options.default_options[:max_threads]
end
end

def test_config_does_not_load_workers_by_default
conf = Puma::Configuration.new
assert_equal 0, conf.options.default_options[:workers]
end

def test_config_loads_workers_from_env
with_env("WEB_CONCURRENCY" => "9") do
conf = Puma::Configuration.new
assert_equal 9, conf.options.default_options[:workers]
end
end

def test_config_does_not_preload_app_if_using_workers
with_env("WEB_CONCURRENCY" => "0") do
conf = Puma::Configuration.new
assert_equal false, conf.options.default_options[:preload_app]
end
end

def test_config_preloads_app_if_using_workers
with_env("WEB_CONCURRENCY" => "2") do
preload = Puma::Plugin.new.workers_supported?
conf = Puma::Configuration.new
assert_equal preload, conf.options.default_options[:preload_app]
end
end
end

class TestConfigFileWithFakeEnv < TestConfigFileBase
def setup
FileUtils.mkpath("config/puma")
Expand Down

0 comments on commit e552e6c

Please sign in to comment.