Skip to content

Commit

Permalink
Give more time in test__socket for server to start up
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Dec 10, 2024
1 parent 2e458f0 commit be22ed9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Tests/modules/network_related/test__socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit be22ed9

Please sign in to comment.