Skip to content

Commit

Permalink
Merge pull request #758 from voxik/report-test-server-issues
Browse files Browse the repository at this point in the history
Prevent test suite lockups on test server failure
  • Loading branch information
geemus committed Aug 27, 2021
2 parents b64de99 + 256c224 commit 4075233
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
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

0 comments on commit 4075233

Please sign in to comment.