From be22ed95e49e27a58c61993d014a5063e9949a21 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Mon, 9 Dec 2024 16:51:50 -0800 Subject: [PATCH] Give more time in test__socket for server to start up --- Tests/modules/network_related/test__socket.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Tests/modules/network_related/test__socket.py b/Tests/modules/network_related/test__socket.py index 626be3d50..b202d5c21 100644 --- a/Tests/modules/network_related/test__socket.py +++ b/Tests/modules/network_related/test__socket.py @@ -533,22 +533,27 @@ def test_misc(self): def test_makefile_refcount(self): "Ensures that the _socket stays open while there's still a file associated" - global PORT + global GPORT + if 'GPORT' in globals(): + del GPORT def echoer(): - global PORT + global GPORT s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state s.settimeout(15) # prevents the server from staying open if the client never connects s.bind(('localhost', 0)) - PORT = s.getsockname()[1] + GPORT = s.getsockname()[1] s.listen(5) (s2, ignore) = s.accept() s2.send(s2.recv(10)) _thread.start_new_thread(echoer, ()) - time.sleep(1) + for _ in range(20): + time.sleep(1) + if 'GPORT' in globals(): + break s = socket.socket() - s.connect(('localhost', PORT)) + s.connect(('localhost', GPORT)) f1 = s.makefile('r') f2 = s.makefile('w') s.close()