From 8c5c5a221f3bd3b0bdf6304b924630c35c7f8631 Mon Sep 17 00:00:00 2001 From: drbrain Date: Wed, 11 Apr 2012 20:28:11 +0000 Subject: * lib/webrick/server.rb (module WEBrick::GenericServer): A server will now continue only when a StandardError subclass is raised. For other exception types the error will be logged at the fatal level and the server will safely stop. Based on a patch by Alex Young. [ruby-trunk - Feature #6236] * test/webrick/test_server.rb: Test for new exception handling behavior. Join the server thread instead of busy-waiting for it to shut down to remove race conditions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/webrick/test_server.rb | 26 ++++++++++++++++++++++++++ test/webrick/utils.rb | 7 +++---- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'test/webrick') diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb index e00449692b..534fe9b077 100644 --- a/test/webrick/test_server.rb +++ b/test/webrick/test_server.rb @@ -23,6 +23,32 @@ class TestWEBrickServer < Test::Unit::TestCase } end + def test_start_exception + stopped = 0 + config = { + :StopCallback => Proc.new{ stopped += 1 }, + } + + e = assert_raises(Exception) do + TestWEBrick.start_server(Echo, config) { |server, addr, port, log| + listener = server.listeners.first + + def listener.accept + raise Exception, 'fatal' # simulate ^C + end + + true while server.status != :Running + + TCPSocket.open(addr, port) { |sock| sock << "foo\n" } + + sleep 0.1 until server.status == :Stop + } + end + + assert_equal('fatal', e.message) + assert_equal(stopped, 1) + end + def test_callbacks accepted = started = stopped = 0 config = { diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb index ef4654cafd..15852ca47d 100644 --- a/test/webrick/utils.rb +++ b/test/webrick/utils.rb @@ -36,14 +36,13 @@ module TestWEBrick :AccessLog => [[logger, ""]] }.update(config)) begin - server.start + server_thread = server.start addr = server.listeners[0].addr block.yield([server, addr[3], addr[1], log]) ensure server.shutdown - until server.status == :Stop - sleep 0.1 - end + + server_thread.join end log_string end -- cgit v1.2.3