Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent test suite lockups on test server failure #758

Merged
merged 1 commit into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/excon/test/plugin/server/exec.rb
Expand Up @@ -4,10 +4,13 @@ module Plugin
module Server
module Exec
def start(app_str = app)
line = ''
open_process(app_str)
process_stderr = ""
line = ''
until line =~ /\Aready\Z/
line = error.gets
raise process_stderr if line.nil?
process_stderr << line
fatal_time = elapsed_time > timeout
if fatal_time
msg = "executable #{app_str} has taken too long to start"
Expand Down
3 changes: 3 additions & 0 deletions lib/excon/test/plugin/server/puma.rb
Expand Up @@ -5,9 +5,12 @@ module Server
module Puma
def start(app_str = app, bind_uri = bind)
open_process('puma', '-b', bind_uri.to_s, app_str)
process_stderr = ""
line = ''
until line =~ /Use Ctrl-C to stop/
line = read.gets
raise process_stderr if line.nil?
process_stderr << line
fatal_time = elapsed_time > timeout
raise 'puma server has taken too long to start' if fatal_time
end
Expand Down
3 changes: 3 additions & 0 deletions lib/excon/test/plugin/server/unicorn.rb
Expand Up @@ -20,9 +20,12 @@ def start(app_str = app, bind_uri = bind)
app_str
]
open_process(*args)
process_stderr = ''
line = ''
until line =~ /worker\=0 ready/
line = error.gets
raise process_stderr if line.nil?
process_stderr << line
fatal_time = elapsed_time > timeout
raise 'unicorn server has taken too long to start' if fatal_time
end
Expand Down
3 changes: 3 additions & 0 deletions lib/excon/test/plugin/server/webrick.rb
Expand Up @@ -8,9 +8,12 @@ def start(app_str = app, bind_uri = bind)
host = bind_uri.host.gsub(/[\[\]]/, '')
port = bind_uri.port.to_s
open_process('rackup', '-s', 'webrick', '--host', host, '--port', port, app_str)
process_stderr = ""
line = ''
until line =~ /HTTPServer#start/
line = error.gets
raise process_stderr if line.nil?
process_stderr << line
fatal_time = elapsed_time > timeout
raise 'webrick server has taken too long to start' if fatal_time
end
Expand Down
18 changes: 15 additions & 3 deletions tests/test_helper.rb
Expand Up @@ -246,7 +246,11 @@ def rackup_path(*parts)

def with_rackup(name, host="127.0.0.1")
pid, w, r, e = launch_process("rackup", "-s", "webrick", "--host", host, rackup_path(name))
until e.gets =~ /HTTPServer#start:/; end
process_stderr = ""
until (line = e.gets) =~ /HTTPServer#start:/
raise process_stderr if line.nil?
process_stderr << line
end
yield
ensure
cleanup_process(pid)
Expand All @@ -271,7 +275,11 @@ def with_unicorn(name, listen='127.0.0.1:9292')
unless RUBY_PLATFORM == 'java'
unix_socket = listen.sub('unix://', '') if listen.start_with? 'unix://'
pid, w, r, e = launch_process("unicorn", "--no-default-middleware","-l", listen, rackup_path(name))
until e.gets =~ /worker=0 ready/; end
process_stderr = ""
until (line = e.gets) =~ /worker=0 ready/
raise process_stderr if line.nil?
process_stderr << line
end
else
# need to find suitable server for jruby
end
Expand All @@ -290,7 +298,11 @@ def server_path(*parts)

def with_server(name)
pid, w, r, e = launch_process("ruby", server_path("#{name}.rb"))
until e.gets =~ /ready/; end
process_stderr = ""
until (line = e.gets) =~ /ready/
raise process_stderr if line.nil?
process_stderr << line
end
yield
ensure
cleanup_process(pid)
Expand Down