summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-12-08 17:09:18 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-12-08 17:09:18 (GMT)
commit576bf65fea78ba6fe41c82f64183b6a8ecdf4643 (patch)
tree1c092926a30e6f15f58d2120c3fe09acd0055e21 /Lib/test
parent99d73f2ce7596be4f1b8909e7255acc5f03ca57b (diff)
downloadcpython-576bf65fea78ba6fe41c82f64183b6a8ecdf4643.zip
cpython-576bf65fea78ba6fe41c82f64183b6a8ecdf4643.tar.gz
cpython-576bf65fea78ba6fe41c82f64183b6a8ecdf4643.tar.bz2
Added stop_serving and a timeout to tearDown()
It prevents the XML RPC tests from blocking until the end of the world. I think it's a backport candidate and other modules may benefit from the feature, too.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_xmlrpc.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 79496c5..f614c76 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -293,6 +293,14 @@ def http_server(evt, numrequests):
PORT = None
evt.set()
+def stop_serving():
+ global PORT
+ if PORT is None:
+ return
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(('localhost', int(PORT)))
+ sock.send(b"")
+ sock.close()
class SimpleServerTestCase(unittest.TestCase):
@@ -315,7 +323,11 @@ class SimpleServerTestCase(unittest.TestCase):
def tearDown(self):
# wait on the server thread to terminate
- self.evt.wait()
+ self.evt.wait(4.0)
+ if not self.evt.isSet():
+ self.evt.set()
+ stop_serving()
+ raise RuntimeError("timeout reached, test has failed")
# disable traceback reporting
SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
@@ -328,7 +340,7 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers))
- def DISABLED_test_404(self):
+ def test_404(self):
# send POST with httplib, it should return 404 header and
# 'Not Found' message.
conn = httplib.HTTPConnection('localhost', PORT)