]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36123: Fix test_socket.testWithTimeoutTriggeredSend() race condition (GH-12053)
authorJoannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
Tue, 26 Feb 2019 16:18:23 +0000 (19:18 +0300)
committerVictor Stinner <vstinner@redhat.com>
Tue, 26 Feb 2019 16:18:23 +0000 (17:18 +0100)
Use longer timeout for accept() in the server and block on accept in the client.
The client now only sets the timeout once the socket is connected.

Lib/test/test_socket.py
Misc/NEWS.d/next/Tests/2019-02-26-12-51-35.bpo-36123.QRhhRS.rst [new file with mode: 0644]

index 7c5167d85033cf96c1208cddde904959151869a6..571f45c2b030cacd7e494626545f8478982cff26 100644 (file)
@@ -5603,7 +5603,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
         support.unlink(support.TESTFN)
 
     def accept_conn(self):
-        self.serv.settimeout(self.TIMEOUT)
+        self.serv.settimeout(MAIN_TIMEOUT)
         conn, addr = self.serv.accept()
         conn.settimeout(self.TIMEOUT)
         self.addCleanup(conn.close)
@@ -5788,7 +5788,8 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
     def _testWithTimeoutTriggeredSend(self):
         address = self.serv.getsockname()
         with open(support.TESTFN, 'rb') as file:
-            with socket.create_connection(address, timeout=0.01) as sock:
+            with socket.create_connection(address) as sock:
+                sock.settimeout(0.01)
                 meth = self.meth_from_sock(sock)
                 self.assertRaises(socket.timeout, meth, file)
 
diff --git a/Misc/NEWS.d/next/Tests/2019-02-26-12-51-35.bpo-36123.QRhhRS.rst b/Misc/NEWS.d/next/Tests/2019-02-26-12-51-35.bpo-36123.QRhhRS.rst
new file mode 100644 (file)
index 0000000..5a7e5bb
--- /dev/null
@@ -0,0 +1 @@
+Fix race condition in test_socket.
\ No newline at end of file