summaryrefslogtreecommitdiff
path: root/test/webrick/test_server.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-11 20:28:11 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-11 20:28:11 +0000
commit8c5c5a221f3bd3b0bdf6304b924630c35c7f8631 (patch)
tree7081865471aecf1d43b45f47c094be8a36168088 /test/webrick/test_server.rb
parent2fe9d4642e4e68538112ea6045cc9a456d7a67b5 (diff)
* 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/test_server.rb')
-rw-r--r--test/webrick/test_server.rb26
1 files changed, 26 insertions, 0 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 = {