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

Fix test__socket, again… #1849

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Changes from all commits
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
20 changes: 11 additions & 9 deletions Tests/modules/network_related/test__socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import time
import unittest

from iptest import IronPythonTestCase, is_cli, is_osx, is_linux, is_windows, is_cpython, run_test
from iptest import IronPythonTestCase, is_cli, is_mono, is_osx, is_linux, is_windows, is_cpython, run_test

AF_DICT = {"AF_APPLETALK" : 5,
"AF_DECnet" : 12,
Expand Down Expand Up @@ -432,7 +432,6 @@ def test_cp5814(self):
HOST = 'localhost'
PORT = 0
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
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(20) # prevents the server from staying open if the client never connects
s.bind((HOST, PORT))
s.listen(1)
Expand Down Expand Up @@ -534,15 +533,14 @@ def test_misc(self):
def test_makefile_refcount(self):
"Ensures that the _socket stays open while there's still a file associated"

GPORT = None
PORT = None
def echoer():
nonlocal GPORT
nonlocal PORT
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))
GPORT = s.getsockname()[1]
s.listen(5)
PORT = s.getsockname()[1]
(s2, _) = s.accept()
s2.send(s2.recv(10))
s2.close()
Expand All @@ -551,11 +549,16 @@ def echoer():
_thread.start_new_thread(echoer, ())
for _ in range(20):
time.sleep(0.5)
if GPORT is not None:
if PORT is not None:
break

if is_mono:
# Warm up Mono to connecting sockets
dummy = socket.socket()
s = socket.socket()
s.connect(('localhost', GPORT))
if is_mono:
dummy.close()
s.connect(('localhost', PORT))
f1 = s.makefile('r')
f2 = s.makefile('w')
s.close()
Expand All @@ -582,7 +585,6 @@ def test_cp7451(self):
HOST = 'localhost'
PORT = 0
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
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(20) # prevents the server from staying open if the client never connects
s.bind((HOST, PORT))
s.listen(1)
Expand Down
Loading