mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Patch Puma::MiniSSL::Socket#read_nonblock
to be non-blocking when using Capybaras Puma server registration - Fix Issue #2227
This commit is contained in:
parent
d82b21a915
commit
8fdc2319e8
2 changed files with 32 additions and 2 deletions
27
lib/capybara/registrations/patches/puma_ssl.rb
Normal file
27
lib/capybara/registrations/patches/puma_ssl.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Puma
|
||||
module MiniSSL
|
||||
class Socket
|
||||
def read_nonblock(size, *_)
|
||||
loop do
|
||||
output = engine_read_all
|
||||
return output if output
|
||||
|
||||
data = @socket.read_nonblock(size, exception: false)
|
||||
raise IO::EAGAINWaitReadable if %i[wait_readable wait_writable].include? data
|
||||
return nil if data.nil?
|
||||
|
||||
@engine.inject(data)
|
||||
output = engine_read_all
|
||||
|
||||
return output if output
|
||||
|
||||
while (neg_data = @engine.extract)
|
||||
@socket.write neg_data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,16 +20,19 @@ Capybara.register_server :puma do |app, port, host, **options|
|
|||
raise LoadError, 'Capybara requires `puma` version 3.8.0 or higher, please upgrade `puma` or register and specify your own server block'
|
||||
end
|
||||
end
|
||||
|
||||
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
|
||||
# Therefore construct and run the Server instance ourselves.
|
||||
# Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
|
||||
default_options = { Host: host, Port: port, Threads: '0:4', workers: 0, daemon: false, queue_requests: false }
|
||||
default_options[:queue_requests] = false if options[:Host]&.start_with?('ssl://')
|
||||
default_options = { Host: host, Port: port, Threads: '0:4', workers: 0, daemon: false}
|
||||
options = default_options.merge(options)
|
||||
|
||||
conf = Rack::Handler::Puma.config(app, options)
|
||||
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
||||
|
||||
puma_ver = Gem::Version.new(Puma::Const::PUMA_VERSION)
|
||||
require_relative 'patches/puma_ssl' if (Gem::Version.new('4.0.0')...Gem::Version.new('4.1.0')).cover? puma_ver
|
||||
|
||||
events.log 'Capybara starting Puma...'
|
||||
events.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
|
||||
events.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"
|
||||
|
|
Loading…
Add table
Reference in a new issue