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:
MSP-Greg 2022-09-30 01:06:32 -05:00 committed by GitHub
parent 673a9e7e89
commit fa65cf7141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 171 additions and 149 deletions

View File

@ -16,17 +16,14 @@ AllCops:
# ————————————————————————————————————————— disabled cops
Performance/RegexpMatch:
Enabled: false
Performance/UnfreezeString:
Enabled: false
Style/RedundantReturn:
Enabled: false
# ————————————————————————————————————————— enabled cops
Layout/AccessModifierIndentation:
EnforcedStyle: indent
Layout/IndentationStyle:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true
@ -43,9 +40,6 @@ Layout/SpaceBeforeFirstArg:
Layout/SpaceInsideParens:
Enabled: true
Layout/IndentationStyle:
Enabled: true
Layout/TrailingEmptyLines:
Enabled: true
@ -55,6 +49,9 @@ Layout/TrailingWhitespace:
Lint/Debugger:
Enabled: true
Metrics/ParameterLists:
Max: 7
Naming/MethodName:
Enabled: true
EnforcedStyle: snake_case
@ -64,17 +61,23 @@ Naming/MethodName:
Naming/VariableName:
Enabled: true
Style/MethodDefParentheses:
Enabled: true
Style/TrailingCommaInArguments:
Enabled: true
Performance:
Enabled: true
Metrics/ParameterLists:
Max: 7
Performance/ChainArrayAllocation:
Enabled: true
Performance/CollectionLiteralInLoop:
Enabled: true
Performance/DeletePrefix:
Enabled: true
Performance/DeleteSuffix:
Enabled: true
Performance/MethodObjectAsBlock:
Enabled: true
Performance/RedundantMatch:
Enabled: true
@ -82,15 +85,26 @@ Performance/RedundantMatch:
Performance/RedundantBlockCall:
Enabled: true
Performance/StringIdentifierArgument:
Enabled: true
Performance/StringInclude:
Enabled: true
Performance/StringReplacement:
Enabled: true
Layout/AccessModifierIndentation:
EnforcedStyle: indent
Style/MethodDefParentheses:
Enabled: true
Style/WhileUntilModifier:
Style/SafeNavigation:
Enabled: true
Style/TernaryParentheses:
Enabled: true
Style/TrailingCommaInArguments:
Enabled: true
Style/WhileUntilModifier:
Enabled: true

View File

@ -124,7 +124,9 @@ module TestPuma
end
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
@ -366,7 +368,7 @@ module TestPuma
# @param summaries [Hash] generated in subclasses
#
def overall_summary(summaries)
names = ''.dup
names = +''
@body_types.each { |_, t_desc| names << t_desc.rjust(8) }
puts "\nBody ────────── req/sec ────────── ─────── req 50% times ───────" \

View File

@ -113,7 +113,7 @@ module TestPuma
def run_summaries(summaries)
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 << ' %8d'

View File

@ -16,7 +16,7 @@ end
module Puma; end
Puma.const_set("WILD_ARGS", ["-I", inc])
Puma.const_set(:WILD_ARGS, ["-I", inc])
require 'puma/cli'

View File

@ -70,7 +70,7 @@ module Puma
# @!attribute [r] connected_ports
# @version 5.0.0
def connected_ports
ios.map { |io| io.addr[1] }.uniq
t = ios.map { |io| io.addr[1] }; t.uniq!; t
end
# @version 5.0.0
@ -96,7 +96,7 @@ module Puma
[:unix, Socket.unpack_sockaddr_un(sock.getsockname)]
rescue ArgumentError # Try to parse as a port/ip
port, addr = Socket.unpack_sockaddr_in(sock.getsockname)
addr = "[#{addr}]" if addr =~ /\:/
addr = "[#{addr}]" if addr&.include? ':'
[:tcp, addr, port]
end
@activated_sockets[key] = sock
@ -216,6 +216,7 @@ module Puma
@listeners << [str, io]
when "ssl"
cert_key = %w[cert key]
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.
# localhost gem will be used for self signed
# 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
end
ctx ||=
begin
# Extract cert_pem and key_pem from options[:store] if present
['cert', 'key'].each do |v|
if params[v] && params[v].start_with?('store:')
cert_key.each do |v|
if params[v]&.start_with?('store:')
index = Integer(params.delete(v).split('store:').last)
params["#{v}_pem"] = @conf.options[:store][index]
end
@ -473,9 +475,10 @@ module Puma
# @!attribute [r] 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?
end.map { |addrinfo| addrinfo.ip_address }.uniq
end
t.map! { |addrinfo| addrinfo.ip_address }; t.uniq!; t
end
def loc_addr_str(io)

View File

@ -355,7 +355,7 @@ module Puma
if cl
# 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}"
end
else
@ -520,7 +520,7 @@ module Puma
# Puma doesn't process chunk extensions, but should parse if they're
# present, which is the reason for the semicolon regex
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}'"
end
len = chunk_hex.to_i(16)

View File

@ -180,10 +180,10 @@ module Puma
end
end
@next_check = [
@workers.reject(&:term?).map(&:ping_timeout).min,
@next_check
].compact.min
t = @workers.reject(&:term?)
t.map!(&:ping_timeout)
@next_check = [t.min, @next_check].compact.min
end
def worker(index, master)
@ -230,7 +230,7 @@ module Puma
def stop_blocked
@status = :stop if @status == :run
wakeup!
@control.stop(true) if @control
@control&.stop true
Process.waitall
end

View File

@ -94,7 +94,7 @@ module Puma
if reuse == true
'&reuse=dflt'
elsif reuse.is_a?(Hash) && (reuse.key?(:size) || reuse.key?(:timeout))
val = ''.dup
val = +''
if (size = reuse[:size]) && Integer === size
val << size.to_s
end

View File

@ -16,7 +16,8 @@ module Puma
def self.chdir_exec(dir, argv)
chdir(dir)
cmd = argv.first
argv = ([:string] * argv.size).zip(argv).flatten
argv = ([:string] * argv.size).zip(argv)
argv.flatten!
argv << :string
argv << nil
execlp(cmd, *argv)

View File

@ -73,14 +73,15 @@ module Puma
end
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))
require_paths_for_gem(spec)
else
log "* Could not load extra dependency: #{dep_name}"
nil
end
end.flatten.compact
end
t.flatten!; t.compact!; t
end
def puma_require_paths

View File

@ -125,7 +125,7 @@ module Puma
while true
wrote = @engine.write data
enc_wr = ''.dup
enc_wr = +''
while (enc = @engine.extract)
enc_wr << enc
end

View File

@ -102,13 +102,13 @@ module Puma::Rack
begin
info = []
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 << "Server-specific options for #{server.name}:"
has_options = false
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]
has_options = true
@ -276,7 +276,7 @@ module Puma::Rack
app = @map ? generate_map(@run, @map) : @run
fail "missing run or map statement" unless app
app = @use.reverse.inject(app) { |a,e| e[a] }
@warmup.call(app) if @warmup
@warmup&.call app
app
end

View File

@ -61,7 +61,7 @@ module Puma
@selector.wakeup
rescue IOError # Ignore if selector is already closed
end
@thread.join if @thread
@thread&.join
end
private
@ -76,7 +76,7 @@ module Puma
# Wakeup all objects that timed out.
timed_out = @timeouts.take_while {|t| t.timeout == 0}
timed_out.each(&method(:wakeup!))
timed_out.each { |c| wakeup! c }
unless @input.empty?
until @input.empty?

View File

@ -213,7 +213,7 @@ module Puma
resp_info = nil
uncork_socket socket
app_body.close if app_body.respond_to? :close
client.tempfile.unlink if client.tempfile
client.tempfile&.unlink
begin
after_reply.each { |o| o.call }
@ -462,7 +462,7 @@ module Puma
# @version 5.0.3
#
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|
next if illegal_header_key?(k)

View File

@ -47,7 +47,7 @@ module Puma
# @version 5.0.0
def stop_control
@control.stop(true) if @control
@control&.stop true
end
def error(str)

View File

@ -196,12 +196,12 @@ module Puma
# @!attribute [r] backlog
def backlog
@thread_pool and @thread_pool.backlog
@thread_pool&.backlog
end
# @!attribute [r] running
def running
@thread_pool and @thread_pool.spawned
@thread_pool&.spawned
end
@ -214,7 +214,7 @@ module Puma
# value would be 4 until it finishes processing.
# @!attribute [r] pool_capacity
def pool_capacity
@thread_pool and @thread_pool.pool_capacity
@thread_pool&.pool_capacity
end
# Runs the server.
@ -230,10 +230,10 @@ module Puma
@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
@reactor = Reactor.new(@io_selector_backend, &method(:reactor_wakeup))
@reactor = Reactor.new(@io_selector_backend) { |c| reactor_wakeup c }
@reactor.run
end

View File

@ -21,21 +21,21 @@ module Puma
end
def restart
@server.begin_restart
@server&.begin_restart
end
def stop
@server.stop(false) if @server
@server&.stop false
end
def halt
@server.halt
@server&.halt
end
def stop_blocked
log "- Gracefully stopping, waiting for requests to finish"
@control.stop(true) if @control
@server.stop(true) if @server
@control&.stop true
@server&.stop true
end
def run

View File

@ -20,7 +20,7 @@ module Puma
end
def save(path, permission = nil)
contents = "---\n".dup
contents = +"---\n"
@options.each do |k,v|
next unless ALLOWED_FIELDS.include? k
case v

View File

@ -163,7 +163,7 @@ module Puma
# @version 5.0.0
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
return false unless @spawned == @waiting
@ -357,8 +357,8 @@ module Puma
@not_empty.broadcast
@not_full.broadcast
@auto_trim.stop if @auto_trim
@reaper.stop if @reaper
@auto_trim&.stop
@reaper&.stop
# dup workers so that we join them all safely
@workers.dup
end

View File

@ -21,7 +21,7 @@ require_relative "helpers/apps"
Thread.abort_on_exception = true
$debugging_info = ''.dup
$debugging_info = +''
$debugging_hold = false # needed for TestCLI#test_control_clustered
$test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do
RUBY_ENGINE == "ruby" ? 45 : 60

View File

@ -34,14 +34,12 @@ class TestIntegration < Minitest::Test
stop_server @pid, signal: :INT
end
if @ios_to_close
@ios_to_close.each do |io|
begin
io.close if io.respond_to?(:close) && !io.closed?
rescue
ensure
io = nil
end
@ios_to_close&.each do |io|
begin
io.close if io.respond_to?(:close) && !io.closed?
rescue
ensure
io = nil
end
end
@ -136,9 +134,9 @@ class TestIntegration < Minitest::Test
if log
puts "Waiting for '#{str}'"
begin
line = @server && @server.gets
puts line if line && !line.strip.empty?
end until line && line.include?(str)
line = @server&.gets
puts line if !line&.strip.empty?
end until line&.include?(str)
else
true until (@server.gets || '').include?(str)
end
@ -163,9 +161,9 @@ class TestIntegration < Minitest::Test
if log
puts "Waiting for '#{re.inspect}'"
begin
line = @server && @server.gets
puts line if line && !line.strip.empty?
end until line && line.match?(re)
line = @server&.gets
puts line if !line&.strip.empty?
end until line&.match?(re)
else
true until (line = @server.gets || '').match?(re)
end
@ -222,7 +220,7 @@ class TestIntegration < Minitest::Test
timeout ||= RESP_READ_TIMEOUT
content_length = nil
chunked = nil
response = ''.dup
response = +''
t_st = Process.clock_gettime Process::CLOCK_MONOTONIC
if connection.to_io.wait_readable timeout
loop do
@ -399,8 +397,10 @@ class TestIntegration < Minitest::Test
if Puma.windows?
cli_pumactl 'stop'
Process.wait @server.pid
@server = nil
else
stop_server
end
@server = nil
msg = (" %4d unexpected_response\n" % replies.fetch(:unexpected_response,0)).dup
msg << " %4d refused\n" % replies.fetch(:refused,0)

View File

@ -12,7 +12,7 @@ module Minitest
class VerboseProgressReporter < Reporter
def prerecord(klass, name)
@current ||= nil
@current = [klass.name, name].tap(&method(:print_start))
@current = [klass.name, name].tap { |t| print_start t }
end
def record(result)

View File

@ -22,11 +22,11 @@ cache_array = {}
run lambda { |env|
info = if (dly = env[hdr_dly])
hash_key = "#{dly},".dup
hash_key = +"#{dly},"
sleep dly.to_f
"#{Process.pid}\nHello World\nSlept #{dly}\n"
else
hash_key = ",".dup
hash_key = +","
"#{Process.pid}\nHello World\n"
end
info_len_adj = 1023 - info.bytesize

View File

@ -22,11 +22,11 @@ cache_chunked = {}
run lambda { |env|
info = if (dly = env[hdr_dly])
hash_key = "#{dly},".dup
hash_key = +"#{dly},"
sleep dly.to_f
"#{Process.pid}\nHello World\nSlept #{dly}\n"
else
hash_key = ",".dup
hash_key = +","
"#{Process.pid}\nHello World\n"
end
info_len_adj = 1023 - info.bytesize

View File

@ -28,12 +28,12 @@ cache_string = {}
run lambda { |env|
info = if (dly = env[hdr_dly])
hash_key = "#{dly},".dup
hash_key = +"#{dly},"
sleep dly.to_f
"#{Process.pid}\nHello World\nSlept #{dly}\n".dup
+"#{Process.pid}\nHello World\nSlept #{dly}\n"
else
hash_key = ",".dup
"#{Process.pid}\nHello World\n".dup
hash_key = +","
+"#{Process.pid}\nHello World\n"
end
info_len_adj = 1023 - info.bytesize

View File

@ -25,12 +25,12 @@ cache_string = {}
run lambda { |env|
info = if (dly = env[hdr_dly])
hash_key = "#{dly},".dup
+hash_key = "#{dly},"
sleep dly.to_f
"#{Process.pid}\nHello World\nSlept #{dly}\n".dup
+"#{Process.pid}\nHello World\nSlept #{dly}\n"
else
hash_key = ",".dup
"#{Process.pid}\nHello World\n".dup
+hash_key = ","
+"#{Process.pid}\nHello World\n"
end
info_len_adj = 1023 - info.bytesize

View File

@ -1,5 +1,5 @@
run lambda { |env|
body = "#{'─' * 70} Headers\n".dup
body = +"#{'─' * 70} Headers\n"
env.sort.each { |k,v| body << "#{k.ljust 30} #{v}\n" }
body << "#{'─' * 78}\n"
[200, {"Content-Type" => "text/plain"}, [body]]

View File

@ -9,7 +9,7 @@ class TestBusyWorker < Minitest::Test
def teardown
return if skipped?
@server.stop(true) if @server
@server&.stop true
@ios.each {|i| i.close unless i.closed?}
end

View File

@ -106,8 +106,9 @@ class TestCLI < Minitest::Test
assert_match(expected_stats, body.split(/\r?\n/).last)
ensure
cli.launcher.stop if cli
t.join if t
# always called, even if skipped
cli&.launcher&.stop
t&.join
end
def test_control_clustered

View File

@ -55,7 +55,7 @@ class TestConfigFile < TestConfigFileBase
app = conf.app
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({})
end

View File

@ -553,7 +553,9 @@ RUBY
read_timeouts = replies.count { |r| r == :read_timeout }
# 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"
@ -630,7 +632,7 @@ RUBY
rescue Errno::ESRCH
nil
end
end.compact
end.compact!
end
# used in loop to create several 'requests'

View File

@ -22,7 +22,7 @@ class TestIntegrationSSLSession < TestIntegration
CERT_PATH = File.expand_path "../examples/puma/client-certs", __dir__
def teardown
@server.close unless @server && @server.closed?
@server.close unless @server&.closed?
@server = nil
super
end

View File

@ -23,7 +23,7 @@ class TestIntegrationSystemd < TestIntegration
def teardown
return if skipped?
@socket.close if @socket
@socket&.close
File.unlink(@sockaddr) if @sockaddr
@socket = nil
@sockaddr = nil

View File

@ -13,7 +13,7 @@ class TestOutOfBandServer < Minitest::Test
def teardown
@oob_finished.broadcast
@app_finished.broadcast
@server.stop(true) if @server
@server&.stop true
@ios.each do |io|
begin

View File

@ -37,7 +37,7 @@ class TestPersistent < Minitest::Test
end
def lines(count, s=@client)
str = "".dup
str = +''
Timeout.timeout(5) do
count.times { str << (s.gets || "") }
end

View File

@ -21,8 +21,8 @@ class TestPumaLocalhostAuthority < Minitest::Test
end
def teardown
@http.finish if @http && @http.started?
@server.stop(true) if @server
@http.finish if @http&.started?
@server&.stop true
end
# yields ctx to block, use for ctx setup & configuration

View File

@ -31,8 +31,8 @@ class TestPumaServerSSL < Minitest::Test
end
def teardown
@http.finish if @http && @http.started?
@server.stop(true) if @server
@http.finish if @http&.started?
@server&.stop true
end
# yields ctx to block, use for ctx setup & configuration
@ -347,7 +347,7 @@ class TestPumaServerSSLClient < Minitest::Test
end
assert_equal subject, log_writer.cert.subject.to_s if subject
ensure
server.stop(true) if server
server&.stop true
end
def test_verify_fail_if_no_client_cert
@ -543,6 +543,6 @@ class TestPumaServerSSLWithCertPemAndKeyPem < Minitest::Test
assert_nil client_error
ensure
server.stop(true) if server
server&.stop true
end
end if ::Puma::HAS_SSL && !Puma::IS_JRUBY

View File

@ -14,7 +14,7 @@ class TestPumaControlCli < TestConfigFileBase
end
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
def teardown
@ -43,71 +43,71 @@ class TestPumaControlCli < TestConfigFileBase
def test_config_file
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"
end
def test_app_env_without_environment
with_env('APP_ENV' => 'test') do
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
def test_rack_env_without_environment
with_env("RACK_ENV" => "test") do
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
def test_app_env_precedence
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => 'production') do
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
with_env('APP_ENV' => nil, 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
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
with_env('APP_ENV' => 'development', 'RACK_ENV' => 'test', 'RAILS_ENV' => 'production') do
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']
assert_equal 'test', control_cli.instance_variable_get('@environment')
assert_equal 'test', control_cli.instance_variable_get(:@environment)
end
end
def test_environment_without_app_env
with_env('APP_ENV' => nil, 'RACK_ENV' => nil, 'RAILS_ENV' => nil) do
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']
assert_equal 'test', control_cli.instance_variable_get('@environment')
assert_equal 'test', control_cli.instance_variable_get(:@environment)
end
end
def test_environment_without_rack_env
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
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"]
assert_equal "test", control_cli.instance_variable_get("@environment")
assert_equal "test", control_cli.instance_variable_get(:@environment)
end
end
def test_environment_with_rack_env
with_env("RACK_ENV" => "production") do
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"]
assert_equal "test", control_cli.instance_variable_get("@environment")
assert_equal "test", control_cli.instance_variable_get(:@environment)
end
end
@ -119,12 +119,12 @@ class TestPumaControlCli < TestConfigFileBase
with_env("RACK_ENV" => nil) do
with_config_file(puma_config_file, port) do
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
with_config_file(production_config_file, port) do
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
@ -137,12 +137,12 @@ class TestPumaControlCli < TestConfigFileBase
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
with_config_file(puma_config_file, port) do
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
with_config_file(development_config_file, port) do
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
@ -154,7 +154,7 @@ class TestPumaControlCli < TestConfigFileBase
]
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
def test_control_url_and_status
@ -204,7 +204,7 @@ class TestPumaControlCli < TestConfigFileBase
"--pid", "1234"
]
cmd = Puma::ControlCLI::NO_REQ_COMMANDS.first
log = ''.dup
log = +''
control_cli = Puma::ControlCLI.new (opts + [cmd]), @ready, @ready
def control_cli.send_signal

View File

@ -43,8 +43,8 @@ if Rack::RELEASE < '3'
yield @launcher
ensure
@launcher.stop if @launcher
thread.join if thread
@launcher&.stop
thread&.join
end
def test_handler_boots

View File

@ -64,6 +64,12 @@ class TestRackServer < Minitest::Test
@server.stop(true) unless @stopped
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
@checker = ErrorChecker.new ServerLint.new(@simple)
@server.app = @checker
@ -135,11 +141,7 @@ class TestRackServer < Minitest::Test
socket.puts "Connection: Keep-Alive\r\n"
socket.puts "\r\n"
headers = socket.readline("\r\n\r\n")
.split("\r\n")
.drop(1)
.map { |line| line.split(/:\s?/) }
.to_h
headers = header_hash socket
content_length = headers["Content-Length"].to_i
real_response_body = socket.read(content_length)
@ -198,11 +200,7 @@ class TestRackServer < Minitest::Test
socket.puts "Connection: Keep-Alive\r\n"
socket.puts "\r\n"
headers = socket.readline("\r\n\r\n")
.split("\r\n")
.drop(1)
.map { |line| line.split(/:\s?/) }
.to_h
headers = header_hash socket
content_length = headers["Content-Length"].to_i

View File

@ -24,7 +24,7 @@ class TestRequestInvalid < Minitest::Test
# this app should never be called, used for debugging
app = ->(env) {
body = ''.dup
body = +''
env.each do |k,v|
body << "#{k} = #{v}\n"
if k == 'rack.input'

View File

@ -103,7 +103,7 @@ class TestWorkerGemIndependence < TestIntegration
initial_reply = read_body(connection)
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__)
Dir.chdir(current_release_symlink) do