Commit ab9a446f authored by Charles-François Natali's avatar Charles-François Natali

Issue #19875: Fix random test_getsockaddrarg() failure.

parents f7152db9 e396c363
...@@ -3,6 +3,7 @@ from test import support ...@@ -3,6 +3,7 @@ from test import support
import errno import errno
import io import io
import itertools
import socket import socket
import select import select
import tempfile import tempfile
...@@ -1147,17 +1148,24 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -1147,17 +1148,24 @@ class GeneralModuleTests(unittest.TestCase):
sock.close() sock.close()
def test_getsockaddrarg(self): def test_getsockaddrarg(self):
host = '0.0.0.0' sock = socket.socket()
self.addCleanup(sock.close)
port = support.find_unused_port() port = support.find_unused_port()
big_port = port + 65536 big_port = port + 65536
neg_port = port - 65536 neg_port = port - 65536
sock = socket.socket() 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: try:
self.assertRaises(OverflowError, sock.bind, (host, big_port)) sock.bind((HOST, port))
self.assertRaises(OverflowError, sock.bind, (host, neg_port)) except OSError as e:
sock.bind((host, port)) if e.errno != errno.EADDRINUSE or i == 5:
finally: raise
sock.close() else:
break
@unittest.skipUnless(os.name == "nt", "Windows specific") @unittest.skipUnless(os.name == "nt", "Windows specific")
def test_sock_ioctl(self): def test_sock_ioctl(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment