Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give more time in test__socket for server to start up #1836

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading