Skip to content

Commit be22ed9

Browse files
committed
Give more time in test__socket for server to start up
1 parent 2e458f0 commit be22ed9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Tests/modules/network_related/test__socket.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,22 +533,27 @@ def test_misc(self):
533533
def test_makefile_refcount(self):
534534
"Ensures that the _socket stays open while there's still a file associated"
535535

536-
global PORT
536+
global GPORT
537+
if 'GPORT' in globals():
538+
del GPORT
537539
def echoer():
538-
global PORT
540+
global GPORT
539541
s = socket.socket()
540542
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
541543
s.settimeout(15) # prevents the server from staying open if the client never connects
542544
s.bind(('localhost', 0))
543-
PORT = s.getsockname()[1]
545+
GPORT = s.getsockname()[1]
544546
s.listen(5)
545547
(s2, ignore) = s.accept()
546548
s2.send(s2.recv(10))
547549

548550
_thread.start_new_thread(echoer, ())
549-
time.sleep(1)
551+
for _ in range(20):
552+
time.sleep(1)
553+
if 'GPORT' in globals():
554+
break
550555
s = socket.socket()
551-
s.connect(('localhost', PORT))
556+
s.connect(('localhost', GPORT))
552557
f1 = s.makefile('r')
553558
f2 = s.makefile('w')
554559
s.close()

0 commit comments

Comments
 (0)