mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Resolve rack.multithread/rack.multiprocess using config
This commit is contained in:
parent
f9ddd58845
commit
47f933d076
3 changed files with 44 additions and 4 deletions
|
@ -6,6 +6,7 @@ require 'socket'
|
|||
require 'puma/const'
|
||||
require 'puma/util'
|
||||
require 'puma/minissl/context_builder'
|
||||
require 'puma/configuration'
|
||||
|
||||
module Puma
|
||||
class Binder
|
||||
|
@ -13,18 +14,19 @@ module Puma
|
|||
|
||||
RACK_VERSION = [1,6].freeze
|
||||
|
||||
def initialize(events)
|
||||
def initialize(events, conf = Configuration.new)
|
||||
@events = events
|
||||
@listeners = []
|
||||
@inherited_fds = {}
|
||||
@activated_sockets = {}
|
||||
@unix_paths = []
|
||||
@conf = conf
|
||||
|
||||
@proto_env = {
|
||||
"rack.version".freeze => RACK_VERSION,
|
||||
"rack.errors".freeze => events.stderr,
|
||||
"rack.multithread".freeze => true,
|
||||
"rack.multiprocess".freeze => false,
|
||||
"rack.multithread".freeze => resolve_option(:multithread, @conf),
|
||||
"rack.multiprocess".freeze => resolve_option(:multiprocess, @conf),
|
||||
"rack.run_once".freeze => false,
|
||||
"SCRIPT_NAME".freeze => ENV['SCRIPT_NAME'] || "",
|
||||
|
||||
|
@ -383,5 +385,14 @@ module Puma
|
|||
def socket_activation_fd(int)
|
||||
int + 3 # 3 is the magic number you add to follow the SA protocol
|
||||
end
|
||||
|
||||
def resolve_option(key, conf)
|
||||
case key
|
||||
when :multithread
|
||||
conf.options[:max_threads] > 1
|
||||
when :multiprocess
|
||||
conf.options[:workers] >= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ module Puma
|
|||
@original_argv = @argv.dup
|
||||
@config = conf
|
||||
|
||||
@binder = Binder.new(@events)
|
||||
@binder = Binder.new(@events, conf)
|
||||
@binder.create_inherited_fds(ENV).each { |k| ENV.delete k }
|
||||
@binder.create_activated_fds(ENV).each { |k| ENV.delete k }
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ require_relative "helpers/ssl"
|
|||
require "puma/binder"
|
||||
require "puma/puma_http11"
|
||||
require "puma/events"
|
||||
require "puma/configuration"
|
||||
|
||||
class TestBinderBase < Minitest::Test
|
||||
include SSLHelper
|
||||
|
@ -295,6 +296,34 @@ class TestBinder < TestBinderBase
|
|||
File.unlink(path) rescue nil # JRuby race?
|
||||
end
|
||||
|
||||
def test_rack_multithread_default_configuration
|
||||
binder = Puma::Binder.new(@events)
|
||||
|
||||
assert binder.proto_env["rack.multithread"]
|
||||
end
|
||||
|
||||
def test_rack_multithread_custom_configuration
|
||||
conf = Puma::Configuration.new(max_threads: 1)
|
||||
|
||||
binder = Puma::Binder.new(@events, conf)
|
||||
|
||||
refute binder.proto_env["rack.multithread"]
|
||||
end
|
||||
|
||||
def test_rack_multiprocess_default_configuration
|
||||
binder = Puma::Binder.new(@events)
|
||||
|
||||
refute binder.proto_env["rack.multiprocess"]
|
||||
end
|
||||
|
||||
def test_rack_multiprocess_custom_configuration
|
||||
conf = Puma::Configuration.new(workers: 1)
|
||||
|
||||
binder = Puma::Binder.new(@events, conf)
|
||||
|
||||
assert binder.proto_env["rack.multiprocess"]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_activates_sockets(path: nil, port: nil, url: nil, sock: nil)
|
||||
|
|
Loading…
Reference in a new issue