The personal finance app for everyone (by everyone)
Ruby
Run Puma in single mode when WEB_CONCURRENCY is 1 (#4658)
Nikolay Kopylov122a01305655
diff --git a/config/puma.rb b/config/puma.rbindex 04022936aa..44b6143066 100644--- a/config/puma.rb+++ b/config/puma.rb@@ -33,7 +33,8 @@ if rails_env == "production"# CPU cores are available. Make sure to set the `WEB_CONCURRENCY` environment# variable to match the number of processors.workers_count = Integer(ENV.fetch("WEB_CONCURRENCY") { 1 })- workers workers_count if workers_count > 1+ # Always set: Puma defaults workers to WEB_CONCURRENCY, so 1 would otherwise start a one-worker cluster.+ workers(workers_count > 1 ? workers_count : 0)preload_app!enddiff --git a/test/config/puma_config_test.rb b/test/config/puma_config_test.rbnew file mode 100644index 0000000000..44f27b85d0--- /dev/null+++ b/test/config/puma_config_test.rb@@ -0,0 +1,25 @@+require "test_helper"+require "puma/configuration"++class PumaConfigTest < ActiveSupport::TestCase+ test "WEB_CONCURRENCY=1 runs a single process, not a one-worker cluster" do+ assert_equal 0, production_workers("WEB_CONCURRENCY" => "1")+ end++ test "an unset WEB_CONCURRENCY runs a single process" do+ assert_equal 0, production_workers("WEB_CONCURRENCY" => nil)+ end++ test "WEB_CONCURRENCY above 1 runs that many workers" do+ assert_equal 3, production_workers("WEB_CONCURRENCY" => "3")+ end++ private+ def production_workers(env)+ with_env_overrides(env.merge("RAILS_ENV" => "production")) do+ config = Puma::Configuration.new({ config_files: [ Rails.root.join("config/puma.rb").to_s ] }, {}, ENV.to_h)+ config.clamp+ config.options[:workers]+ end+ end+end