diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-11 20:28:11 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-11 20:28:11 +0000 |
commit | 8c5c5a221f3bd3b0bdf6304b924630c35c7f8631 (patch) | |
tree | 7081865471aecf1d43b45f47c094be8a36168088 /test/webrick | |
parent | 2fe9d4642e4e68538112ea6045cc9a456d7a67b5 (diff) | |
download | ruby-8c5c5a221f3bd3b0bdf6304b924630c35c7f8631.tar.gz |
* 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
Diffstat (limited to 'test/webrick')
-rw-r--r-- | test/webrick/test_server.rb | 26 | ||||
-rw-r--r-- | test/webrick/utils.rb | 7 |
2 files changed, 29 insertions, 4 deletions
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 |