103 RuboCop fixes (#2976)
* rubocop.yml - add more Cops & alphabetize * RuboCop - Performance/UnfreezeString * RuboCop - Style/SafeNavigation * RuboCop - Performance/StringInclude * RuboCop - Performance/StringIdentifierArgument * RuboCop - Performance/RegexpMatch * RuboCop - Performance/MethodObjectAsBlock * RuboCop - Performance/CollectionLiteralInLoop * RuboCop - Performance/ChainArrayAllocation
This commit is contained in:
parent
673a9e7e89
commit
fa65cf7141
60
.rubocop.yml
60
.rubocop.yml
|
@ -16,17 +16,14 @@ AllCops:
|
||||||
|
|
||||||
# ————————————————————————————————————————— disabled cops
|
# ————————————————————————————————————————— disabled cops
|
||||||
|
|
||||||
Performance/RegexpMatch:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Performance/UnfreezeString:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/RedundantReturn:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# ————————————————————————————————————————— enabled cops
|
# ————————————————————————————————————————— enabled cops
|
||||||
|
|
||||||
|
Layout/AccessModifierIndentation:
|
||||||
|
EnforcedStyle: indent
|
||||||
|
|
||||||
|
Layout/IndentationStyle:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Layout/SpaceAfterColon:
|
Layout/SpaceAfterColon:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
@ -43,9 +40,6 @@ Layout/SpaceBeforeFirstArg:
|
||||||
Layout/SpaceInsideParens:
|
Layout/SpaceInsideParens:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Layout/IndentationStyle:
|
|
||||||
Enabled: true
|
|
||||||
|
|
||||||
Layout/TrailingEmptyLines:
|
Layout/TrailingEmptyLines:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
@ -55,6 +49,9 @@ Layout/TrailingWhitespace:
|
||||||
Lint/Debugger:
|
Lint/Debugger:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Metrics/ParameterLists:
|
||||||
|
Max: 7
|
||||||
|
|
||||||
Naming/MethodName:
|
Naming/MethodName:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
EnforcedStyle: snake_case
|
EnforcedStyle: snake_case
|
||||||
|
@ -64,17 +61,23 @@ Naming/MethodName:
|
||||||
Naming/VariableName:
|
Naming/VariableName:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Style/MethodDefParentheses:
|
|
||||||
Enabled: true
|
|
||||||
|
|
||||||
Style/TrailingCommaInArguments:
|
|
||||||
Enabled: true
|
|
||||||
|
|
||||||
Performance:
|
Performance:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Metrics/ParameterLists:
|
Performance/ChainArrayAllocation:
|
||||||
Max: 7
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/CollectionLiteralInLoop:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/DeletePrefix:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/DeleteSuffix:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/MethodObjectAsBlock:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Performance/RedundantMatch:
|
Performance/RedundantMatch:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
@ -82,15 +85,26 @@ Performance/RedundantMatch:
|
||||||
Performance/RedundantBlockCall:
|
Performance/RedundantBlockCall:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/StringIdentifierArgument:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/StringInclude:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Performance/StringReplacement:
|
Performance/StringReplacement:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Layout/AccessModifierIndentation:
|
Style/MethodDefParentheses:
|
||||||
EnforcedStyle: indent
|
Enabled: true
|
||||||
|
|
||||||
Style/WhileUntilModifier:
|
Style/SafeNavigation:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Style/TernaryParentheses:
|
Style/TernaryParentheses:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Style/TrailingCommaInArguments:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Style/WhileUntilModifier:
|
||||||
|
Enabled: true
|
||||||
|
|
|
@ -124,7 +124,9 @@ module TestPuma
|
||||||
end
|
end
|
||||||
|
|
||||||
if (sizes = arg[SIZES_RE])
|
if (sizes = arg[SIZES_RE])
|
||||||
@body_sizes = sizes.split(',').map(&:to_i).sort
|
@body_sizes = sizes.split(',')
|
||||||
|
@body_sizes.map!(&:to_i)
|
||||||
|
@body_sizes.sort!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -366,7 +368,7 @@ module TestPuma
|
||||||
# @param summaries [Hash] generated in subclasses
|
# @param summaries [Hash] generated in subclasses
|
||||||
#
|
#
|
||||||
def overall_summary(summaries)
|
def overall_summary(summaries)
|
||||||
names = ''.dup
|
names = +''
|
||||||
@body_types.each { |_, t_desc| names << t_desc.rjust(8) }
|
@body_types.each { |_, t_desc| names << t_desc.rjust(8) }
|
||||||
|
|
||||||
puts "\nBody ────────── req/sec ────────── ─────── req 50% times ───────" \
|
puts "\nBody ────────── req/sec ────────── ─────── req 50% times ───────" \
|
||||||
|
|
|
@ -113,7 +113,7 @@ module TestPuma
|
||||||
def run_summaries(summaries)
|
def run_summaries(summaries)
|
||||||
digits = [4 - Math.log10(@max_100_time).to_i, 3].min
|
digits = [4 - Math.log10(@max_100_time).to_i, 3].min
|
||||||
|
|
||||||
fmt_vals = "%-6s %6d".dup
|
fmt_vals = +'%-6s %6d'
|
||||||
fmt_vals << (digits < 0 ? " %6d" : " %6.#{digits}f")*5
|
fmt_vals << (digits < 0 ? " %6d" : " %6.#{digits}f")*5
|
||||||
fmt_vals << ' %8d'
|
fmt_vals << ' %8d'
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
|
|
||||||
module Puma; end
|
module Puma; end
|
||||||
|
|
||||||
Puma.const_set("WILD_ARGS", ["-I", inc])
|
Puma.const_set(:WILD_ARGS, ["-I", inc])
|
||||||
|
|
||||||
require 'puma/cli'
|
require 'puma/cli'
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ module Puma
|
||||||
# @!attribute [r] connected_ports
|
# @!attribute [r] connected_ports
|
||||||
# @version 5.0.0
|
# @version 5.0.0
|
||||||
def connected_ports
|
def connected_ports
|
||||||
ios.map { |io| io.addr[1] }.uniq
|
t = ios.map { |io| io.addr[1] }; t.uniq!; t
|
||||||
end
|
end
|
||||||
|
|
||||||
# @version 5.0.0
|
# @version 5.0.0
|
||||||
|
@ -96,7 +96,7 @@ module Puma
|
||||||
[:unix, Socket.unpack_sockaddr_un(sock.getsockname)]
|
[:unix, Socket.unpack_sockaddr_un(sock.getsockname)]
|
||||||
rescue ArgumentError # Try to parse as a port/ip
|
rescue ArgumentError # Try to parse as a port/ip
|
||||||
port, addr = Socket.unpack_sockaddr_in(sock.getsockname)
|
port, addr = Socket.unpack_sockaddr_in(sock.getsockname)
|
||||||
addr = "[#{addr}]" if addr =~ /\:/
|
addr = "[#{addr}]" if addr&.include? ':'
|
||||||
[:tcp, addr, port]
|
[:tcp, addr, port]
|
||||||
end
|
end
|
||||||
@activated_sockets[key] = sock
|
@activated_sockets[key] = sock
|
||||||
|
@ -216,6 +216,7 @@ module Puma
|
||||||
|
|
||||||
@listeners << [str, io]
|
@listeners << [str, io]
|
||||||
when "ssl"
|
when "ssl"
|
||||||
|
cert_key = %w[cert key]
|
||||||
|
|
||||||
raise "Puma compiled without SSL support" unless HAS_SSL
|
raise "Puma compiled without SSL support" unless HAS_SSL
|
||||||
|
|
||||||
|
@ -224,15 +225,16 @@ module Puma
|
||||||
# If key and certs are not defined and localhost gem is required.
|
# If key and certs are not defined and localhost gem is required.
|
||||||
# localhost gem will be used for self signed
|
# localhost gem will be used for self signed
|
||||||
# Load localhost authority if not loaded.
|
# Load localhost authority if not loaded.
|
||||||
if params.values_at('cert', 'key').all? { |v| v.to_s.empty? }
|
# Ruby 3 `values_at` accepts an array, earlier do not
|
||||||
|
if params.values_at(*cert_key).all? { |v| v.to_s.empty? }
|
||||||
ctx = localhost_authority && localhost_authority_context
|
ctx = localhost_authority && localhost_authority_context
|
||||||
end
|
end
|
||||||
|
|
||||||
ctx ||=
|
ctx ||=
|
||||||
begin
|
begin
|
||||||
# Extract cert_pem and key_pem from options[:store] if present
|
# Extract cert_pem and key_pem from options[:store] if present
|
||||||
['cert', 'key'].each do |v|
|
cert_key.each do |v|
|
||||||
if params[v] && params[v].start_with?('store:')
|
if params[v]&.start_with?('store:')
|
||||||
index = Integer(params.delete(v).split('store:').last)
|
index = Integer(params.delete(v).split('store:').last)
|
||||||
params["#{v}_pem"] = @conf.options[:store][index]
|
params["#{v}_pem"] = @conf.options[:store][index]
|
||||||
end
|
end
|
||||||
|
@ -473,9 +475,10 @@ module Puma
|
||||||
|
|
||||||
# @!attribute [r] loopback_addresses
|
# @!attribute [r] loopback_addresses
|
||||||
def loopback_addresses
|
def loopback_addresses
|
||||||
Socket.ip_address_list.select do |addrinfo|
|
t = Socket.ip_address_list.select do |addrinfo|
|
||||||
addrinfo.ipv6_loopback? || addrinfo.ipv4_loopback?
|
addrinfo.ipv6_loopback? || addrinfo.ipv4_loopback?
|
||||||
end.map { |addrinfo| addrinfo.ip_address }.uniq
|
end
|
||||||
|
t.map! { |addrinfo| addrinfo.ip_address }; t.uniq!; t
|
||||||
end
|
end
|
||||||
|
|
||||||
def loc_addr_str(io)
|
def loc_addr_str(io)
|
||||||
|
|
|
@ -355,7 +355,7 @@ module Puma
|
||||||
|
|
||||||
if cl
|
if cl
|
||||||
# cannot contain characters that are not \d
|
# cannot contain characters that are not \d
|
||||||
if cl =~ CONTENT_LENGTH_VALUE_INVALID
|
if CONTENT_LENGTH_VALUE_INVALID.match? cl
|
||||||
raise HttpParserError, "Invalid Content-Length: #{cl.inspect}"
|
raise HttpParserError, "Invalid Content-Length: #{cl.inspect}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -520,7 +520,7 @@ module Puma
|
||||||
# Puma doesn't process chunk extensions, but should parse if they're
|
# Puma doesn't process chunk extensions, but should parse if they're
|
||||||
# present, which is the reason for the semicolon regex
|
# present, which is the reason for the semicolon regex
|
||||||
chunk_hex = line.strip[/\A[^;]+/]
|
chunk_hex = line.strip[/\A[^;]+/]
|
||||||
if chunk_hex =~ CHUNK_SIZE_INVALID
|
if CHUNK_SIZE_INVALID.match? chunk_hex
|
||||||
raise HttpParserError, "Invalid chunk size: '#{chunk_hex}'"
|
raise HttpParserError, "Invalid chunk size: '#{chunk_hex}'"
|
||||||
end
|
end
|
||||||
len = chunk_hex.to_i(16)
|
len = chunk_hex.to_i(16)
|
||||||
|
|
|
@ -180,10 +180,10 @@ module Puma
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@next_check = [
|
t = @workers.reject(&:term?)
|
||||||
@workers.reject(&:term?).map(&:ping_timeout).min,
|
t.map!(&:ping_timeout)
|
||||||
@next_check
|
|
||||||
].compact.min
|
@next_check = [t.min, @next_check].compact.min
|
||||||
end
|
end
|
||||||
|
|
||||||
def worker(index, master)
|
def worker(index, master)
|
||||||
|
@ -230,7 +230,7 @@ module Puma
|
||||||
def stop_blocked
|
def stop_blocked
|
||||||
@status = :stop if @status == :run
|
@status = :stop if @status == :run
|
||||||
wakeup!
|
wakeup!
|
||||||
@control.stop(true) if @control
|
@control&.stop true
|
||||||
Process.waitall
|
Process.waitall
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ module Puma
|
||||||
if reuse == true
|
if reuse == true
|
||||||
'&reuse=dflt'
|
'&reuse=dflt'
|
||||||
elsif reuse.is_a?(Hash) && (reuse.key?(:size) || reuse.key?(:timeout))
|
elsif reuse.is_a?(Hash) && (reuse.key?(:size) || reuse.key?(:timeout))
|
||||||
val = ''.dup
|
val = +''
|
||||||
if (size = reuse[:size]) && Integer === size
|
if (size = reuse[:size]) && Integer === size
|
||||||
val << size.to_s
|
val << size.to_s
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,8 @@ module Puma
|
||||||
def self.chdir_exec(dir, argv)
|
def self.chdir_exec(dir, argv)
|
||||||
chdir(dir)
|
chdir(dir)
|
||||||
cmd = argv.first
|
cmd = argv.first
|
||||||
argv = ([:string] * argv.size).zip(argv).flatten
|
argv = ([:string] * argv.size).zip(argv)
|
||||||
|
argv.flatten!
|
||||||
argv << :string
|
argv << :string
|
||||||
argv << nil
|
argv << nil
|
||||||
execlp(cmd, *argv)
|
execlp(cmd, *argv)
|
||||||
|
|
|
@ -73,14 +73,15 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def extra_runtime_deps_paths
|
def extra_runtime_deps_paths
|
||||||
@extra_runtime_dependencies.map do |dep_name|
|
t = @extra_runtime_dependencies.map do |dep_name|
|
||||||
if (spec = spec_for_gem(dep_name))
|
if (spec = spec_for_gem(dep_name))
|
||||||
require_paths_for_gem(spec)
|
require_paths_for_gem(spec)
|
||||||
else
|
else
|
||||||
log "* Could not load extra dependency: #{dep_name}"
|
log "* Could not load extra dependency: #{dep_name}"
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end.flatten.compact
|
end
|
||||||
|
t.flatten!; t.compact!; t
|
||||||
end
|
end
|
||||||
|
|
||||||
def puma_require_paths
|
def puma_require_paths
|
||||||
|
|
|
@ -125,7 +125,7 @@ module Puma
|
||||||
while true
|
while true
|
||||||
wrote = @engine.write data
|
wrote = @engine.write data
|
||||||
|
|
||||||
enc_wr = ''.dup
|
enc_wr = +''
|
||||||
while (enc = @engine.extract)
|
while (enc = @engine.extract)
|
||||||
enc_wr << enc
|
enc_wr << enc
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,13 +102,13 @@ module Puma::Rack
|
||||||
begin
|
begin
|
||||||
info = []
|
info = []
|
||||||
server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
|
server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
|
||||||
if server && server.respond_to?(:valid_options)
|
if server&.respond_to?(:valid_options)
|
||||||
info << ""
|
info << ""
|
||||||
info << "Server-specific options for #{server.name}:"
|
info << "Server-specific options for #{server.name}:"
|
||||||
|
|
||||||
has_options = false
|
has_options = false
|
||||||
server.valid_options.each do |name, description|
|
server.valid_options.each do |name, description|
|
||||||
next if name.to_s =~ /^(Host|Port)[^a-zA-Z]/ # ignore handler's host and port options, we do our own.
|
next if /^(Host|Port)[^a-zA-Z]/.match? name.to_s # ignore handler's host and port options, we do our own.
|
||||||
|
|
||||||
info << " -O %-21s %s" % [name, description]
|
info << " -O %-21s %s" % [name, description]
|
||||||
has_options = true
|
has_options = true
|
||||||
|
@ -276,7 +276,7 @@ module Puma::Rack
|
||||||
app = @map ? generate_map(@run, @map) : @run
|
app = @map ? generate_map(@run, @map) : @run
|
||||||
fail "missing run or map statement" unless app
|
fail "missing run or map statement" unless app
|
||||||
app = @use.reverse.inject(app) { |a,e| e[a] }
|
app = @use.reverse.inject(app) { |a,e| e[a] }
|
||||||
@warmup.call(app) if @warmup
|
@warmup&.call app
|
||||||
app
|
app
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ module Puma
|
||||||
@selector.wakeup
|
@selector.wakeup
|
||||||
rescue IOError # Ignore if selector is already closed
|
rescue IOError # Ignore if selector is already closed
|
||||||
end
|
end
|
||||||
@thread.join if @thread
|
@thread&.join
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -76,7 +76,7 @@ module Puma
|
||||||
|
|
||||||
# Wakeup all objects that timed out.
|
# Wakeup all objects that timed out.
|
||||||
timed_out = @timeouts.take_while {|t| t.timeout == 0}
|
timed_out = @timeouts.take_while {|t| t.timeout == 0}
|
||||||
timed_out.each(&method(:wakeup!))
|
timed_out.each { |c| wakeup! c }
|
||||||
|
|
||||||
unless @input.empty?
|
unless @input.empty?
|
||||||
until @input.empty?
|
until @input.empty?
|
||||||
|
|
|
@ -213,7 +213,7 @@ module Puma
|
||||||
resp_info = nil
|
resp_info = nil
|
||||||
uncork_socket socket
|
uncork_socket socket
|
||||||
app_body.close if app_body.respond_to? :close
|
app_body.close if app_body.respond_to? :close
|
||||||
client.tempfile.unlink if client.tempfile
|
client.tempfile&.unlink
|
||||||
|
|
||||||
begin
|
begin
|
||||||
after_reply.each { |o| o.call }
|
after_reply.each { |o| o.call }
|
||||||
|
@ -462,7 +462,7 @@ module Puma
|
||||||
# @version 5.0.3
|
# @version 5.0.3
|
||||||
#
|
#
|
||||||
def str_early_hints(headers)
|
def str_early_hints(headers)
|
||||||
eh_str = "HTTP/1.1 103 Early Hints\r\n".dup
|
eh_str = +"HTTP/1.1 103 Early Hints\r\n"
|
||||||
headers.each_pair do |k, vs|
|
headers.each_pair do |k, vs|
|
||||||
next if illegal_header_key?(k)
|
next if illegal_header_key?(k)
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ module Puma
|
||||||
|
|
||||||
# @version 5.0.0
|
# @version 5.0.0
|
||||||
def stop_control
|
def stop_control
|
||||||
@control.stop(true) if @control
|
@control&.stop true
|
||||||
end
|
end
|
||||||
|
|
||||||
def error(str)
|
def error(str)
|
||||||
|
|
|
@ -196,12 +196,12 @@ module Puma
|
||||||
|
|
||||||
# @!attribute [r] backlog
|
# @!attribute [r] backlog
|
||||||
def backlog
|
def backlog
|
||||||
@thread_pool and @thread_pool.backlog
|
@thread_pool&.backlog
|
||||||
end
|
end
|
||||||
|
|
||||||
# @!attribute [r] running
|
# @!attribute [r] running
|
||||||
def running
|
def running
|
||||||
@thread_pool and @thread_pool.spawned
|
@thread_pool&.spawned
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ module Puma
|
||||||
# value would be 4 until it finishes processing.
|
# value would be 4 until it finishes processing.
|
||||||
# @!attribute [r] pool_capacity
|
# @!attribute [r] pool_capacity
|
||||||
def pool_capacity
|
def pool_capacity
|
||||||
@thread_pool and @thread_pool.pool_capacity
|
@thread_pool&.pool_capacity
|
||||||
end
|
end
|
||||||
|
|
||||||
# Runs the server.
|
# Runs the server.
|
||||||
|
@ -230,10 +230,10 @@ module Puma
|
||||||
|
|
||||||
@status = :run
|
@status = :run
|
||||||
|
|
||||||
@thread_pool = ThreadPool.new(thread_name, @options, &method(:process_client))
|
@thread_pool = ThreadPool.new(thread_name, @options) { |a, b| process_client a, b }
|
||||||
|
|
||||||
if @queue_requests
|
if @queue_requests
|
||||||
@reactor = Reactor.new(@io_selector_backend, &method(:reactor_wakeup))
|
@reactor = Reactor.new(@io_selector_backend) { |c| reactor_wakeup c }
|
||||||
@reactor.run
|
@reactor.run
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,21 +21,21 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def restart
|
def restart
|
||||||
@server.begin_restart
|
@server&.begin_restart
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
@server.stop(false) if @server
|
@server&.stop false
|
||||||
end
|
end
|
||||||
|
|
||||||
def halt
|
def halt
|
||||||
@server.halt
|
@server&.halt
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop_blocked
|
def stop_blocked
|
||||||
log "- Gracefully stopping, waiting for requests to finish"
|
log "- Gracefully stopping, waiting for requests to finish"
|
||||||
@control.stop(true) if @control
|
@control&.stop true
|
||||||
@server.stop(true) if @server
|
@server&.stop true
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def save(path, permission = nil)
|
def save(path, permission = nil)
|
||||||
contents = "---\n".dup
|
contents = +"---\n"
|
||||||
@options.each do |k,v|
|
@options.each do |k,v|
|
||||||
next unless ALLOWED_FIELDS.include? k
|
next unless ALLOWED_FIELDS.include? k
|
||||||
case v
|
case v
|
||||||
|
|
|
@ -163,7 +163,7 @@ module Puma
|
||||||
|
|
||||||
# @version 5.0.0
|
# @version 5.0.0
|
||||||
def trigger_out_of_band_hook
|
def trigger_out_of_band_hook
|
||||||
return false unless @out_of_band && @out_of_band.any?
|
return false unless @out_of_band&.any?
|
||||||
|
|
||||||
# we execute on idle hook when all threads are free
|
# we execute on idle hook when all threads are free
|
||||||
return false unless @spawned == @waiting
|
return false unless @spawned == @waiting
|
||||||
|
@ -357,8 +357,8 @@ module Puma
|
||||||
@not_empty.broadcast
|
@not_empty.broadcast
|
||||||
@not_full.broadcast
|
@not_full.broadcast
|
||||||
|
|
||||||
@auto_trim.stop if @auto_trim
|
@auto_trim&.stop
|
||||||
@reaper.stop if @reaper
|
@reaper&.stop
|
||||||
# dup workers so that we join them all safely
|
# dup workers so that we join them all safely
|
||||||
@workers.dup
|
@workers.dup
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ require_relative "helpers/apps"
|
||||||
|
|
||||||
Thread.abort_on_exception = true
|
Thread.abort_on_exception = true
|
||||||
|
|
||||||
$debugging_info = ''.dup
|
$debugging_info = +''
|
||||||
$debugging_hold = false # needed for TestCLI#test_control_clustered
|
$debugging_hold = false # needed for TestCLI#test_control_clustered
|
||||||
$test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do
|
$test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do
|
||||||
RUBY_ENGINE == "ruby" ? 45 : 60
|
RUBY_ENGINE == "ruby" ? 45 : 60
|
||||||
|
|
|
@ -34,14 +34,12 @@ class TestIntegration < Minitest::Test
|
||||||
stop_server @pid, signal: :INT
|
stop_server @pid, signal: :INT
|
||||||
end
|
end
|
||||||
|
|
||||||
if @ios_to_close
|
@ios_to_close&.each do |io|
|
||||||
@ios_to_close.each do |io|
|
begin
|
||||||
begin
|
io.close if io.respond_to?(:close) && !io.closed?
|
||||||
io.close if io.respond_to?(:close) && !io.closed?
|
rescue
|
||||||
rescue
|
ensure
|
||||||
ensure
|
io = nil
|
||||||
io = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,9 +134,9 @@ class TestIntegration < Minitest::Test
|
||||||
if log
|
if log
|
||||||
puts "Waiting for '#{str}'"
|
puts "Waiting for '#{str}'"
|
||||||
begin
|
begin
|
||||||
line = @server && @server.gets
|
line = @server&.gets
|
||||||
puts line if line && !line.strip.empty?
|
puts line if !line&.strip.empty?
|
||||||
end until line && line.include?(str)
|
end until line&.include?(str)
|
||||||
else
|
else
|
||||||
true until (@server.gets || '').include?(str)
|
true until (@server.gets || '').include?(str)
|
||||||
end
|
end
|
||||||
|
@ -163,9 +161,9 @@ class TestIntegration < Minitest::Test
|
||||||
if log
|
if log
|
||||||
puts "Waiting for '#{re.inspect}'"
|
puts "Waiting for '#{re.inspect}'"
|
||||||
begin
|
begin
|
||||||
line = @server && @server.gets
|
line = @server&.gets
|
||||||
puts line if line && !line.strip.empty?
|
puts line if !line&.strip.empty?
|
||||||
end until line && line.match?(re)
|
end until line&.match?(re)
|
||||||
else
|
else
|
||||||
true until (line = @server.gets || '').match?(re)
|
true until (line = @server.gets || '').match?(re)
|
||||||
end
|
end
|
||||||
|
@ -222,7 +220,7 @@ class TestIntegration < Minitest::Test
|
||||||
timeout ||= RESP_READ_TIMEOUT
|
timeout ||= RESP_READ_TIMEOUT
|
||||||
content_length = nil
|
content_length = nil
|
||||||
chunked = nil
|
chunked = nil
|
||||||
response = ''.dup
|
response = +''
|
||||||
t_st = Process.clock_gettime Process::CLOCK_MONOTONIC
|
t_st = Process.clock_gettime Process::CLOCK_MONOTONIC
|
||||||
if connection.to_io.wait_readable timeout
|
if connection.to_io.wait_readable timeout
|
||||||
loop do
|
loop do
|
||||||
|
@ -399,8 +397,10 @@ class TestIntegration < Minitest::Test
|
||||||
if Puma.windows?
|
if Puma.windows?
|
||||||
cli_pumactl 'stop'
|
cli_pumactl 'stop'
|
||||||
Process.wait @server.pid
|
Process.wait @server.pid
|
||||||
@server = nil
|
else
|
||||||
|
stop_server
|
||||||
end
|
end
|
||||||
|
@server = nil
|
||||||
|
|
||||||
msg = (" %4d unexpected_response\n" % replies.fetch(:unexpected_response,0)).dup
|
msg = (" %4d unexpected_response\n" % replies.fetch(:unexpected_response,0)).dup
|
||||||
msg << " %4d refused\n" % replies.fetch(:refused,0)
|
msg << " %4d refused\n" % replies.fetch(:refused,0)
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Minitest
|
||||||
class VerboseProgressReporter < Reporter
|
class VerboseProgressReporter < Reporter
|
||||||
def prerecord(klass, name)
|
def prerecord(klass, name)
|
||||||
@current ||= nil
|
@current ||= nil
|
||||||
@current = [klass.name, name].tap(&method(:print_start))
|
@current = [klass.name, name].tap { |t| print_start t }
|
||||||
end
|
end
|
||||||
|
|
||||||
def record(result)
|
def record(result)
|
||||||
|
|
|
@ -22,11 +22,11 @@ cache_array = {}
|
||||||
|
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
info = if (dly = env[hdr_dly])
|
info = if (dly = env[hdr_dly])
|
||||||
hash_key = "#{dly},".dup
|
hash_key = +"#{dly},"
|
||||||
sleep dly.to_f
|
sleep dly.to_f
|
||||||
"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
||||||
else
|
else
|
||||||
hash_key = ",".dup
|
hash_key = +","
|
||||||
"#{Process.pid}\nHello World\n"
|
"#{Process.pid}\nHello World\n"
|
||||||
end
|
end
|
||||||
info_len_adj = 1023 - info.bytesize
|
info_len_adj = 1023 - info.bytesize
|
||||||
|
|
|
@ -22,11 +22,11 @@ cache_chunked = {}
|
||||||
|
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
info = if (dly = env[hdr_dly])
|
info = if (dly = env[hdr_dly])
|
||||||
hash_key = "#{dly},".dup
|
hash_key = +"#{dly},"
|
||||||
sleep dly.to_f
|
sleep dly.to_f
|
||||||
"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
||||||
else
|
else
|
||||||
hash_key = ",".dup
|
hash_key = +","
|
||||||
"#{Process.pid}\nHello World\n"
|
"#{Process.pid}\nHello World\n"
|
||||||
end
|
end
|
||||||
info_len_adj = 1023 - info.bytesize
|
info_len_adj = 1023 - info.bytesize
|
||||||
|
|
|
@ -28,12 +28,12 @@ cache_string = {}
|
||||||
|
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
info = if (dly = env[hdr_dly])
|
info = if (dly = env[hdr_dly])
|
||||||
hash_key = "#{dly},".dup
|
hash_key = +"#{dly},"
|
||||||
sleep dly.to_f
|
sleep dly.to_f
|
||||||
"#{Process.pid}\nHello World\nSlept #{dly}\n".dup
|
+"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
||||||
else
|
else
|
||||||
hash_key = ",".dup
|
hash_key = +","
|
||||||
"#{Process.pid}\nHello World\n".dup
|
+"#{Process.pid}\nHello World\n"
|
||||||
end
|
end
|
||||||
info_len_adj = 1023 - info.bytesize
|
info_len_adj = 1023 - info.bytesize
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ cache_string = {}
|
||||||
|
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
info = if (dly = env[hdr_dly])
|
info = if (dly = env[hdr_dly])
|
||||||
hash_key = "#{dly},".dup
|
+hash_key = "#{dly},"
|
||||||
sleep dly.to_f
|
sleep dly.to_f
|
||||||
"#{Process.pid}\nHello World\nSlept #{dly}\n".dup
|
+"#{Process.pid}\nHello World\nSlept #{dly}\n"
|
||||||
else
|
else
|
||||||
hash_key = ",".dup
|
+hash_key = ","
|
||||||
"#{Process.pid}\nHello World\n".dup
|
+"#{Process.pid}\nHello World\n"
|
||||||
end
|
end
|
||||||
info_len_adj = 1023 - info.bytesize
|
info_len_adj = 1023 - info.bytesize
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
body = "#{'─' * 70} Headers\n".dup
|
body = +"#{'─' * 70} Headers\n"
|
||||||
env.sort.each { |k,v| body << "#{k.ljust 30} #{v}\n" }
|
env.sort.each { |k,v| body << "#{k.ljust 30} #{v}\n" }
|
||||||
body << "#{'─' * 78}\n"
|
body << "#{'─' * 78}\n"
|
||||||
[200, {"Content-Type" => "text/plain"}, [body]]
|
[200, {"Content-Type" => "text/plain"}, [body]]
|
||||||
|
|
|
@ -9,7 +9,7 @@ class TestBusyWorker < Minitest::Test
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
return if skipped?
|
return if skipped?
|
||||||
@server.stop(true) if @server
|
@server&.stop true
|
||||||
@ios.each {|i| i.close unless i.closed?}
|
@ios.each {|i| i.close unless i.closed?}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,9 @@ class TestCLI < Minitest::Test
|
||||||
assert_match(expected_stats, body.split(/\r?\n/).last)
|
assert_match(expected_stats, body.split(/\r?\n/).last)
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
cli.launcher.stop if cli
|
# always called, even if skipped
|
||||||
t.join if t
|
cli&.launcher&.stop
|
||||||
|
t&.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_control_clustered
|
def test_control_clustered
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TestConfigFile < TestConfigFileBase
|
||||||
app = conf.app
|
app = conf.app
|
||||||
|
|
||||||
assert bind_configuration =~ %r{ca=.*ca.crt}
|
assert bind_configuration =~ %r{ca=.*ca.crt}
|
||||||
assert bind_configuration =~ /verify_mode=peer/
|
assert bind_configuration&.include?('verify_mode=peer')
|
||||||
|
|
||||||
assert_equal [200, {}, ["embedded app"]], app.call({})
|
assert_equal [200, {}, ["embedded app"]], app.call({})
|
||||||
end
|
end
|
||||||
|
|
|
@ -553,7 +553,9 @@ RUBY
|
||||||
read_timeouts = replies.count { |r| r == :read_timeout }
|
read_timeouts = replies.count { |r| r == :read_timeout }
|
||||||
|
|
||||||
# get pids from replies, generate uniq array
|
# get pids from replies, generate uniq array
|
||||||
qty_pids = replies.map { |body| body[/\d+\z/] }.uniq.compact.length
|
t = replies.map { |body| body[/\d+\z/] }
|
||||||
|
t.uniq!; t.compact!
|
||||||
|
qty_pids = t.length
|
||||||
|
|
||||||
msg = "#{responses} responses, #{qty_pids} uniq pids"
|
msg = "#{responses} responses, #{qty_pids} uniq pids"
|
||||||
|
|
||||||
|
@ -630,7 +632,7 @@ RUBY
|
||||||
rescue Errno::ESRCH
|
rescue Errno::ESRCH
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end.compact
|
end.compact!
|
||||||
end
|
end
|
||||||
|
|
||||||
# used in loop to create several 'requests'
|
# used in loop to create several 'requests'
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestIntegrationSSLSession < TestIntegration
|
||||||
CERT_PATH = File.expand_path "../examples/puma/client-certs", __dir__
|
CERT_PATH = File.expand_path "../examples/puma/client-certs", __dir__
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@server.close unless @server && @server.closed?
|
@server.close unless @server&.closed?
|
||||||
@server = nil
|
@server = nil
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TestIntegrationSystemd < TestIntegration
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
return if skipped?
|
return if skipped?
|
||||||
@socket.close if @socket
|
@socket&.close
|
||||||
File.unlink(@sockaddr) if @sockaddr
|
File.unlink(@sockaddr) if @sockaddr
|
||||||
@socket = nil
|
@socket = nil
|
||||||
@sockaddr = nil
|
@sockaddr = nil
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TestOutOfBandServer < Minitest::Test
|
||||||
def teardown
|
def teardown
|
||||||
@oob_finished.broadcast
|
@oob_finished.broadcast
|
||||||
@app_finished.broadcast
|
@app_finished.broadcast
|
||||||
@server.stop(true) if @server
|
@server&.stop true
|
||||||
|
|
||||||
@ios.each do |io|
|
@ios.each do |io|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -37,7 +37,7 @@ class TestPersistent < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def lines(count, s=@client)
|
def lines(count, s=@client)
|
||||||
str = "".dup
|
str = +''
|
||||||
Timeout.timeout(5) do
|
Timeout.timeout(5) do
|
||||||
count.times { str << (s.gets || "") }
|
count.times { str << (s.gets || "") }
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,8 +21,8 @@ class TestPumaLocalhostAuthority < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@http.finish if @http && @http.started?
|
@http.finish if @http&.started?
|
||||||
@server.stop(true) if @server
|
@server&.stop true
|
||||||
end
|
end
|
||||||
|
|
||||||
# yields ctx to block, use for ctx setup & configuration
|
# yields ctx to block, use for ctx setup & configuration
|
||||||
|
|
|
@ -31,8 +31,8 @@ class TestPumaServerSSL < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@http.finish if @http && @http.started?
|
@http.finish if @http&.started?
|
||||||
@server.stop(true) if @server
|
@server&.stop true
|
||||||
end
|
end
|
||||||
|
|
||||||
# yields ctx to block, use for ctx setup & configuration
|
# yields ctx to block, use for ctx setup & configuration
|
||||||
|
@ -347,7 +347,7 @@ class TestPumaServerSSLClient < Minitest::Test
|
||||||
end
|
end
|
||||||
assert_equal subject, log_writer.cert.subject.to_s if subject
|
assert_equal subject, log_writer.cert.subject.to_s if subject
|
||||||
ensure
|
ensure
|
||||||
server.stop(true) if server
|
server&.stop true
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_verify_fail_if_no_client_cert
|
def test_verify_fail_if_no_client_cert
|
||||||
|
@ -543,6 +543,6 @@ class TestPumaServerSSLWithCertPemAndKeyPem < Minitest::Test
|
||||||
|
|
||||||
assert_nil client_error
|
assert_nil client_error
|
||||||
ensure
|
ensure
|
||||||
server.stop(true) if server
|
server&.stop true
|
||||||
end
|
end
|
||||||
end if ::Puma::HAS_SSL && !Puma::IS_JRUBY
|
end if ::Puma::HAS_SSL && !Puma::IS_JRUBY
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_booted
|
def wait_booted
|
||||||
line = @wait.gets until line =~ /Use Ctrl-C to stop/
|
line = @wait.gets until line&.include?('Use Ctrl-C to stop')
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
@ -43,71 +43,71 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
|
|
||||||
def test_config_file
|
def test_config_file
|
||||||
control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
|
control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
|
||||||
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
|
assert_equal "t3-pid", control_cli.instance_variable_get(:@pidfile)
|
||||||
File.unlink "t3-pid" if File.file? "t3-pid"
|
File.unlink "t3-pid" if File.file? "t3-pid"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_app_env_without_environment
|
def test_app_env_without_environment
|
||||||
with_env('APP_ENV' => 'test') do
|
with_env('APP_ENV' => 'test') do
|
||||||
control_cli = Puma::ControlCLI.new ['halt']
|
control_cli = Puma::ControlCLI.new ['halt']
|
||||||
assert_equal 'test', control_cli.instance_variable_get('@environment')
|
assert_equal 'test', control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rack_env_without_environment
|
def test_rack_env_without_environment
|
||||||
with_env("RACK_ENV" => "test") do
|
with_env("RACK_ENV" => "test") do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal "test", control_cli.instance_variable_get("@environment")
|
assert_equal "test", control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_app_env_precedence
|
def test_app_env_precedence
|
||||||
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => 'production') do
|
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => 'production') do
|
||||||
control_cli = Puma::ControlCLI.new ['halt']
|
control_cli = Puma::ControlCLI.new ['halt']
|
||||||
assert_equal 'production', control_cli.instance_variable_get('@environment')
|
assert_equal 'production', control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_env('APP_ENV' => nil, 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
|
with_env('APP_ENV' => nil, 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
|
||||||
control_cli = Puma::ControlCLI.new ['halt']
|
control_cli = Puma::ControlCLI.new ['halt']
|
||||||
assert_equal 'test', control_cli.instance_variable_get('@environment')
|
assert_equal 'test', control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_env('APP_ENV' => 'development', 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
|
with_env('APP_ENV' => 'development', 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
|
||||||
control_cli = Puma::ControlCLI.new ['halt']
|
control_cli = Puma::ControlCLI.new ['halt']
|
||||||
assert_equal 'development', control_cli.instance_variable_get('@environment')
|
assert_equal 'development', control_cli.instance_variable_get(:@environment)
|
||||||
|
|
||||||
control_cli = Puma::ControlCLI.new ['-e', 'test', 'halt']
|
control_cli = Puma::ControlCLI.new ['-e', 'test', 'halt']
|
||||||
assert_equal 'test', control_cli.instance_variable_get('@environment')
|
assert_equal 'test', control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_without_app_env
|
def test_environment_without_app_env
|
||||||
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => nil) do
|
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => nil) do
|
||||||
control_cli = Puma::ControlCLI.new ['halt']
|
control_cli = Puma::ControlCLI.new ['halt']
|
||||||
assert_nil control_cli.instance_variable_get('@environment')
|
assert_nil control_cli.instance_variable_get(:@environment)
|
||||||
|
|
||||||
control_cli = Puma::ControlCLI.new ['-e', 'test', 'halt']
|
control_cli = Puma::ControlCLI.new ['-e', 'test', 'halt']
|
||||||
assert_equal 'test', control_cli.instance_variable_get('@environment')
|
assert_equal 'test', control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_without_rack_env
|
def test_environment_without_rack_env
|
||||||
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
|
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_nil control_cli.instance_variable_get("@environment")
|
assert_nil control_cli.instance_variable_get(:@environment)
|
||||||
|
|
||||||
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
||||||
assert_equal "test", control_cli.instance_variable_get("@environment")
|
assert_equal "test", control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_with_rack_env
|
def test_environment_with_rack_env
|
||||||
with_env("RACK_ENV" => "production") do
|
with_env("RACK_ENV" => "production") do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal "production", control_cli.instance_variable_get("@environment")
|
assert_equal "production", control_cli.instance_variable_get(:@environment)
|
||||||
|
|
||||||
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
||||||
assert_equal "test", control_cli.instance_variable_get("@environment")
|
assert_equal "test", control_cli.instance_variable_get(:@environment)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,12 +119,12 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
with_env("RACK_ENV" => nil) do
|
with_env("RACK_ENV" => nil) do
|
||||||
with_config_file(puma_config_file, port) do
|
with_config_file(puma_config_file, port) do
|
||||||
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
||||||
assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")
|
assert_equal puma_config_file, control_cli.instance_variable_get(:@config_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_config_file(production_config_file, port) do
|
with_config_file(production_config_file, port) do
|
||||||
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
||||||
assert_equal production_config_file, control_cli.instance_variable_get("@config_file")
|
assert_equal production_config_file, control_cli.instance_variable_get(:@config_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,12 +137,12 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
|
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
|
||||||
with_config_file(puma_config_file, port) do
|
with_config_file(puma_config_file, port) do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")
|
assert_equal puma_config_file, control_cli.instance_variable_get(:@config_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_config_file(development_config_file, port) do
|
with_config_file(development_config_file, port) do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal development_config_file, control_cli.instance_variable_get("@config_file")
|
assert_equal development_config_file, control_cli.instance_variable_get(:@config_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -154,7 +154,7 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
]
|
]
|
||||||
|
|
||||||
control_cli = Puma::ControlCLI.new opts, @ready, @ready
|
control_cli = Puma::ControlCLI.new opts, @ready, @ready
|
||||||
assert_equal 'none', control_cli.instance_variable_get("@control_auth_token")
|
assert_equal 'none', control_cli.instance_variable_get(:@control_auth_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_control_url_and_status
|
def test_control_url_and_status
|
||||||
|
@ -204,7 +204,7 @@ class TestPumaControlCli < TestConfigFileBase
|
||||||
"--pid", "1234"
|
"--pid", "1234"
|
||||||
]
|
]
|
||||||
cmd = Puma::ControlCLI::NO_REQ_COMMANDS.first
|
cmd = Puma::ControlCLI::NO_REQ_COMMANDS.first
|
||||||
log = ''.dup
|
log = +''
|
||||||
control_cli = Puma::ControlCLI.new (opts + [cmd]), @ready, @ready
|
control_cli = Puma::ControlCLI.new (opts + [cmd]), @ready, @ready
|
||||||
|
|
||||||
def control_cli.send_signal
|
def control_cli.send_signal
|
||||||
|
|
|
@ -43,8 +43,8 @@ if Rack::RELEASE < '3'
|
||||||
|
|
||||||
yield @launcher
|
yield @launcher
|
||||||
ensure
|
ensure
|
||||||
@launcher.stop if @launcher
|
@launcher&.stop
|
||||||
thread.join if thread
|
thread&.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handler_boots
|
def test_handler_boots
|
||||||
|
|
|
@ -64,6 +64,12 @@ class TestRackServer < Minitest::Test
|
||||||
@server.stop(true) unless @stopped
|
@server.stop(true) unless @stopped
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def header_hash(socket)
|
||||||
|
t = socket.readline("\r\n\r\n").split("\r\n")
|
||||||
|
t.shift; t.map! { |line| line.split(/:\s?/) }
|
||||||
|
t.to_h
|
||||||
|
end
|
||||||
|
|
||||||
def test_lint
|
def test_lint
|
||||||
@checker = ErrorChecker.new ServerLint.new(@simple)
|
@checker = ErrorChecker.new ServerLint.new(@simple)
|
||||||
@server.app = @checker
|
@server.app = @checker
|
||||||
|
@ -135,11 +141,7 @@ class TestRackServer < Minitest::Test
|
||||||
socket.puts "Connection: Keep-Alive\r\n"
|
socket.puts "Connection: Keep-Alive\r\n"
|
||||||
socket.puts "\r\n"
|
socket.puts "\r\n"
|
||||||
|
|
||||||
headers = socket.readline("\r\n\r\n")
|
headers = header_hash socket
|
||||||
.split("\r\n")
|
|
||||||
.drop(1)
|
|
||||||
.map { |line| line.split(/:\s?/) }
|
|
||||||
.to_h
|
|
||||||
|
|
||||||
content_length = headers["Content-Length"].to_i
|
content_length = headers["Content-Length"].to_i
|
||||||
real_response_body = socket.read(content_length)
|
real_response_body = socket.read(content_length)
|
||||||
|
@ -198,11 +200,7 @@ class TestRackServer < Minitest::Test
|
||||||
socket.puts "Connection: Keep-Alive\r\n"
|
socket.puts "Connection: Keep-Alive\r\n"
|
||||||
socket.puts "\r\n"
|
socket.puts "\r\n"
|
||||||
|
|
||||||
headers = socket.readline("\r\n\r\n")
|
headers = header_hash socket
|
||||||
.split("\r\n")
|
|
||||||
.drop(1)
|
|
||||||
.map { |line| line.split(/:\s?/) }
|
|
||||||
.to_h
|
|
||||||
|
|
||||||
content_length = headers["Content-Length"].to_i
|
content_length = headers["Content-Length"].to_i
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TestRequestInvalid < Minitest::Test
|
||||||
|
|
||||||
# this app should never be called, used for debugging
|
# this app should never be called, used for debugging
|
||||||
app = ->(env) {
|
app = ->(env) {
|
||||||
body = ''.dup
|
body = +''
|
||||||
env.each do |k,v|
|
env.each do |k,v|
|
||||||
body << "#{k} = #{v}\n"
|
body << "#{k} = #{v}\n"
|
||||||
if k == 'rack.input'
|
if k == 'rack.input'
|
||||||
|
|
|
@ -103,7 +103,7 @@ class TestWorkerGemIndependence < TestIntegration
|
||||||
initial_reply = read_body(connection)
|
initial_reply = read_body(connection)
|
||||||
assert_equal old_version, initial_reply
|
assert_equal old_version, initial_reply
|
||||||
|
|
||||||
before_restart.call if before_restart
|
before_restart&.call
|
||||||
|
|
||||||
set_release_symlink File.expand_path(new_app_dir, __dir__)
|
set_release_symlink File.expand_path(new_app_dir, __dir__)
|
||||||
Dir.chdir(current_release_symlink) do
|
Dir.chdir(current_release_symlink) do
|
||||||
|
|
Loading…
Reference in New Issue