1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Revert change to Server#initialize (new) method signature from #2798 (#2965)

* Revert change to `Server#initialize` (new) method signature from #2798

* Test changes for updated Server#intialize
This commit is contained in:
MSP-Greg 2022-09-20 21:11:13 -05:00 committed by GitHub
parent 2b56d801cc
commit 2fbb09626a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 34 additions and 31 deletions

View file

@ -46,6 +46,8 @@ module Puma
@original_argv = @argv.dup
@config = conf
@config.options[:log_writer] = @log_writer
# Advertise the Configuration
Puma.cli_config = @config if defined?(Puma.cli_config)

View file

@ -69,7 +69,7 @@ module Puma
app = Puma::App::Status.new @launcher, token
control = Puma::Server.new app, @log_writer, @events,
control = Puma::Server.new app, @events,
{ min_threads: 0, max_threads: 1, queue_requests: false }
control.binder.parse [str], self, 'Starting control server'
@ -167,7 +167,7 @@ module Puma
end
def start_server
server = Puma::Server.new(app, @log_writer, @events, @options)
server = Puma::Server.new(app, @events, @options)
server.inherit_binder(@launcher.binder)
server
end

View file

@ -67,10 +67,13 @@ module Puma
# and have default values set via +fetch+. Normally the values are set via
# `::Puma::Configuration.puma_default_options`.
#
def initialize(app, log_writer=LogWriter.stdio, events=Events.new, options = {})
# @note The `events` parameter is set to nil, and set to `Events.new` in code.
# Often `options` needs to be passed, but `events` does not. Using nil allows
# calling code to not require events.rb.
#
def initialize(app, events = nil, options = {})
@app = app
@log_writer = log_writer
@events = events
@events = events || Events.new
@check, @notify = nil
@status = :stop
@ -84,6 +87,7 @@ module Puma
UserFileDefaultOptions.new(options, Configuration::DEFAULTS)
end
@log_writer = @options.fetch :log_writer, LogWriter.stdio
@early_hints = @options[:early_hints]
@first_data_timeout = @options[:first_data_timeout]
@min_threads = @options[:min_threads]

View file

@ -1,5 +1,4 @@
require_relative "helper"
require "puma/events"
class TestBusyWorker < Minitest::Test
def setup
@ -55,8 +54,9 @@ class TestBusyWorker < Minitest::Test
options[:min_threads] ||= 0
options[:max_threads] ||= 10
options[:log_writer] ||= Puma::LogWriter.strings
@server = Puma::Server.new request_handler, Puma::LogWriter.strings, Puma::Events.new, **options
@server = Puma::Server.new request_handler, nil, **options
@port = (@server.add_tcp_listener '127.0.0.1', 0).addr[1]
@server.run
end

View file

@ -1,6 +1,5 @@
require_relative 'helper'
require_relative "helpers/integration"
require "puma/log_writer"
# These tests are used to verify that Puma works with SSL sockets. Only
# integration tests isolate the server from the test environment, so there
@ -99,7 +98,7 @@ RUBY
app = lambda { |_| [200, { 'Content-Type' => 'text/plain' }, ["HELLO", ' ', "THERE"]] }
opts = {max_threads: 1}
server = Puma::Server.new app, Puma::LogWriter.stdio, Puma::Events.new, opts
server = Puma::Server.new app, nil, opts
if Puma.jruby?
ssl_params = {
'keystore' => File.expand_path('../examples/puma/client-certs/keystore.jks', __dir__),

View file

@ -1,3 +1,4 @@
require 'puma/detect'
require 'puma/log_writer'
require_relative "helper"
@ -124,7 +125,7 @@ class TestLogWriter < Minitest::Test
def test_parse_error
app = proc { |_env| [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }
log_writer = Puma::LogWriter.strings
server = Puma::Server.new app, log_writer
server = Puma::Server.new app, nil, {log_writer: log_writer}
host = '127.0.0.1'
port = (server.add_tcp_listener host, 0).addr[1]

View file

@ -1,5 +1,4 @@
require_relative "helper"
require "puma/events"
class TestOutOfBandServer < Minitest::Test
parallelize_me!
@ -69,8 +68,9 @@ class TestOutOfBandServer < Minitest::Test
options[:min_threads] ||= 1
options[:max_threads] ||= 1
options[:log_writer] ||= Puma::LogWriter.strings
@server = Puma::Server.new app, Puma::LogWriter.strings, Puma::Events.new, out_of_band: [oob], **options
@server = Puma::Server.new app, nil, out_of_band: [oob], **options
@port = (@server.add_tcp_listener '127.0.0.1', 0).addr[1]
@server.run
sleep 0.15 if Puma.jruby?

View file

@ -1,5 +1,4 @@
require_relative "helper"
require "puma/log_writer"
class TestPersistent < Minitest::Test
@ -25,7 +24,7 @@ class TestPersistent < Minitest::Test
end
opts = {max_threads: 1}
@server = Puma::Server.new @simple, Puma::LogWriter.stdio, Puma::Events.new, opts
@server = Puma::Server.new @simple, nil, opts
@port = (@server.add_tcp_listener HOST, 0).addr[1]
@server.run
sleep 0.15 if Puma.jruby?

View file

@ -31,8 +31,7 @@ class TestPumaLocalhostAuthority < Minitest::Test
app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
@log_writer = SSLLogWriterHelper.new STDOUT, STDERR
@server = Puma::Server.new app, @log_writer
@server.app = app
@server = Puma::Server.new app, nil, {log_writer: @log_writer}
@server.add_ssl_listener @host, 0, nil
@http = Net::HTTP.new @host, @server.connected_ports[0]
@ -63,7 +62,7 @@ class TestPumaSSLLocalhostAuthority < Minitest::Test
@log_writer = SSLLogWriterHelper.new STDOUT, STDERR
@server = Puma::Server.new app, @log_writer
@server = Puma::Server.new app, nil, {log_writer: @log_writer}
@server.app = app
@server.add_ssl_listener @host, 0,nil

View file

@ -17,7 +17,7 @@ class TestPumaServer < Minitest::Test
@log_writer = Puma::LogWriter.strings
@events = Puma::Events.new
@server = Puma::Server.new @app, @log_writer, @events
@server = Puma::Server.new @app, @events, {log_writer: @log_writer}
end
def teardown
@ -26,8 +26,9 @@ class TestPumaServer < Minitest::Test
end
def server_run(**options, &block)
options[:log_writer] ||= @log_writer
options[:min_threads] ||= 1
@server = Puma::Server.new block || @app, @log_writer, @events, options
@server = Puma::Server.new block || @app, @events, options
@port = (@server.add_tcp_listener @host, 0).addr[1]
@server.run
sleep 0.15 if Puma.jruby?
@ -400,7 +401,7 @@ EOF
def test_lowlevel_error_message
skip_if :windows
@server = Puma::Server.new @app, @log_writer, @events, {:force_shutdown_after => 2}
@server = Puma::Server.new @app, @events, {log_writer: @log_writer, :force_shutdown_after => 2}
server_run do
if TestSkips::TRUFFLE
@ -547,7 +548,7 @@ EOF
end
def test_no_timeout_after_data_received_no_queue
@server = Puma::Server.new @app, @log_writer, @events, queue_requests: false
@server = Puma::Server.new @app, @events, {log_writer: @log_writer, queue_requests: false}
test_no_timeout_after_data_received
end
@ -1369,7 +1370,7 @@ EOF
def test_custom_io_selector
backend = NIO::Selector.backends.first
@server = Puma::Server.new @app, @log_writer, @events, {:io_selector_backend => backend}
@server = Puma::Server.new @app, @events, {log_writer: @log_writer, :io_selector_backend => backend}
@server.run
selector = @server.instance_variable_get(:@reactor).instance_variable_get(:@selector)

View file

@ -56,7 +56,7 @@ class TestPumaServerSSL < Minitest::Test
yield ctx if block_given?
@log_writer = SSLLogWriterHelper.new STDOUT, STDERR
@server = Puma::Server.new app, @log_writer
@server = Puma::Server.new app, nil, {log_writer: @log_writer}
@port = (@server.add_ssl_listener @host, 0, ctx).addr[1]
@server.run
@ -315,7 +315,7 @@ class TestPumaServerSSLClient < Minitest::Test
app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
log_writer = SSLLogWriterHelper.new STDOUT, STDERR
server = Puma::Server.new app, log_writer
server = Puma::Server.new app, nil, {log_writer: log_writer}
server.add_ssl_listener host, port, context
host_addrs = server.binder.ios.map { |io| io.to_io.addr[2] }
server.run
@ -520,7 +520,7 @@ class TestPumaServerSSLWithCertPemAndKeyPem < Minitest::Test
app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
log_writer = SSLLogWriterHelper.new STDOUT, STDERR
server = Puma::Server.new app, log_writer
server = Puma::Server.new app, nil, {log_writer: log_writer}
server.add_ssl_listener host, port, ctx
server.run

View file

@ -1,5 +1,4 @@
require_relative "helper"
require "puma/events"
# These tests check for invalid request headers and metadata.
# Content-Length, Transfer-Encoding, and chunked body size
@ -36,8 +35,7 @@ class TestRequestInvalid < Minitest::Test
}
@log_writer = Puma::LogWriter.strings
events = Puma::Events.new
@server = Puma::Server.new app, @log_writer, events
@server = Puma::Server.new app, nil, {log_writer: @log_writer}
@port = (@server.add_tcp_listener @host, 0).addr[1]
@server.run
sleep 0.15 if Puma.jruby?

View file

@ -17,7 +17,7 @@ class TestResponseHeader < Minitest::Test
@app = ->(env) { [200, {}, [env['rack.url_scheme']]] }
@log_writer = Puma::LogWriter.strings
@server = Puma::Server.new @app, @log_writer, ::Puma::Events.new, {min_threads: 1}
@server = Puma::Server.new @app, ::Puma::Events.new, {log_writer: @log_writer, min_threads: 1}
end
def teardown

View file

@ -23,7 +23,7 @@ class WebServerTest < Minitest::Test
def setup
@tester = TestHandler.new
@server = Puma::Server.new @tester, Puma::LogWriter.strings
@server = Puma::Server.new @tester, nil, {log_writer: Puma::LogWriter.strings}
@port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1]
@tcp = "http://127.0.0.1:#{@port}"
@server.run