diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2014-07-25 17:45:28 (GMT) |
---|---|---|
committer | Charles-François Natali <cf.natali@gmail.com> | 2014-07-25 17:45:28 (GMT) |
commit | ab9a446f234c5b8417c13dfebb12db72defd246c (patch) | |
tree | be2f8d2845f6f7f56a7e72d9fdb21eecc423c5e4 /Lib | |
parent | f7152db99fbbeccec7ca734535836a9605cf932a (diff) | |
parent | e396c363cbacce68d7750a7963af4d7cd3bf30e7 (diff) | |
download | cpython-ab9a446f234c5b8417c13dfebb12db72defd246c.zip cpython-ab9a446f234c5b8417c13dfebb12db72defd246c.tar.gz cpython-ab9a446f234c5b8417c13dfebb12db72defd246c.tar.bz2 |
Issue #19875: Fix random test_getsockaddrarg() failure.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_socket.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 950d0dc..e9043fa 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3,6 +3,7 @@ from test import support import errno import io +import itertools import socket import select import tempfile @@ -1147,17 +1148,24 @@ class GeneralModuleTests(unittest.TestCase): sock.close() def test_getsockaddrarg(self): - host = '0.0.0.0' + sock = socket.socket() + self.addCleanup(sock.close) port = support.find_unused_port() big_port = port + 65536 neg_port = port - 65536 - sock = socket.socket() - try: - self.assertRaises(OverflowError, sock.bind, (host, big_port)) - self.assertRaises(OverflowError, sock.bind, (host, neg_port)) - sock.bind((host, port)) - finally: - sock.close() + self.assertRaises(OverflowError, sock.bind, (HOST, big_port)) + self.assertRaises(OverflowError, sock.bind, (HOST, neg_port)) + # Since find_unused_port() is inherently subject to race conditions, we + # call it a couple times if necessary. + for i in itertools.count(): + port = support.find_unused_port() + try: + sock.bind((HOST, port)) + except OSError as e: + if e.errno != errno.EADDRINUSE or i == 5: + raise + else: + break @unittest.skipUnless(os.name == "nt", "Windows specific") def test_sock_ioctl(self): |