]> granicus.if.org Git - python/commitdiff
Add test for previous core dump when sending on closed socket with
authorGuido van Rossum <guido@python.org>
Fri, 19 Jul 2002 12:46:46 +0000 (12:46 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 19 Jul 2002 12:46:46 +0000 (12:46 +0000)
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

index b9b9db69eadc8c62d53909f8987b30317a8fd57e..d3589663bb5617e436fe348630da06b37953645c 100644 (file)
@@ -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):