[Python-checkins] bpo-36123: Fix test_socket.testWithTimeoutTriggeredSend() race condition (GH-12053)
Victor Stinner
webhook-mailer at python.org
Tue Feb 26 11:18:27 EST 2019
https://github.com/python/cpython/commit/53b9e1a1c1d86187ad6fbee492b697ef8be74205
commit: 53b9e1a1c1d86187ad6fbee492b697ef8be74205
branch: master
author: Joannah Nanjekye <33177550+nanjekyejoannah at users.noreply.github.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019-02-26T17:18:23+01:00
summary:
bpo-36123: Fix test_socket.testWithTimeoutTriggeredSend() race condition (GH-12053)
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.
files:
A Misc/NEWS.d/next/Tests/2019-02-26-12-51-35.bpo-36123.QRhhRS.rst
M Lib/test/test_socket.py
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 7c5167d85033..571f45c2b030 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -5603,7 +5603,7 @@ def tearDownClass(cls):
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 @@ def testWithTimeout(self):
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
index 000000000000..5a7e5bb8f43c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-02-26-12-51-35.bpo-36123.QRhhRS.rst
@@ -0,0 +1 @@
+Fix race condition in test_socket.
\ No newline at end of file
More information about the Python-checkins
mailing list