diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 30992efd..da88acb6 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,10 +137,9 @@ module Puma @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 @@ -174,8 +173,7 @@ module Puma end def default_max_threads - return 5 if Puma.mri? - 16 + Puma.mri? ? 5 : 16 end def puma_default_options @@ -186,7 +184,6 @@ module Puma :debug => false, :binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"], :workers => Integer(ENV['WEB_CONCURRENCY'] || 0), - :daemon => false, :mode => :http, :worker_timeout => DefaultWorkerTimeout, :worker_boot_timeout => DefaultWorkerTimeout, diff --git a/test/test_config.rb b/test/test_config.rb index 8de59b05..b78a65f7 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -6,6 +6,7 @@ require_relative "helpers/config_file" require "puma/configuration" require 'puma/events' + class TestConfigFile < TestConfigFileBase parallelize_me! @@ -15,51 +16,6 @@ class TestConfigFile < TestConfigFileBase 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| @@ -327,6 +283,65 @@ class TestEnvModifificationConfig < TestConfigFileBase 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 + 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")