From b6cc7d2806d0e7784abf8479bfed3543de48bb97 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 19 Jul 2002 12:46:46 +0000 Subject: Add test for previous core dump when sending on closed socket with timeout. Added small sleeps to _testAccept() and _testRecv() in NonBlockingTCPTests, to reduce race conditions (I know, this is not the solution!) --- Lib/test/test_socket.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index b9b9db6..d358966 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -325,7 +325,7 @@ class GeneralModuleTests(unittest.TestCase): # Check that setting it to an invalid type raises TypeError self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") - # XXX The following three don't test module-level functionality... + # XXX The following don't test module-level functionality... def testSockName(self): """Testing getsockname().""" @@ -348,6 +348,13 @@ class GeneralModuleTests(unittest.TestCase): reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) self.failIf(reuse == 0, "failed to set reuse mode") + def testSendAfterClose(self): + """testing send() after close() with timeout.""" + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(1) + sock.close() + self.assertRaises(socket.error, sock.send, "spam") + class BasicTCPTest(SocketConnectedTest): def __init__(self, methodName='runTest'): @@ -486,6 +493,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest): self.fail("Error trying to do accept after select.") def _testAccept(self): + time.sleep(0.1) self.cli.connect((HOST, PORT)) def testConnect(self): @@ -515,6 +523,7 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest): def _testRecv(self): self.cli.connect((HOST, PORT)) + time.sleep(0.1) self.cli.send(MSG) class FileObjectClassTestCase(SocketConnectedTest): -- cgit v0.12