Skip to content

Commit 7a6252b

Browse files
authored
Fix test__socket, again… (#1849)
* Fix test__socket, again... * Clean up test
1 parent e104794 commit 7a6252b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Tests/modules/network_related/test__socket.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import time
1414
import unittest
1515

16-
from iptest import IronPythonTestCase, is_cli, is_osx, is_linux, is_windows, is_cpython, run_test
16+
from iptest import IronPythonTestCase, is_cli, is_mono, is_osx, is_linux, is_windows, is_cpython, run_test
1717

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

537-
GPORT = None
536+
PORT = None
538537
def echoer():
539-
nonlocal GPORT
538+
nonlocal PORT
540539
s = socket.socket()
541-
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
542540
s.settimeout(15) # prevents the server from staying open if the client never connects
543541
s.bind(('localhost', 0))
544-
GPORT = s.getsockname()[1]
545542
s.listen(5)
543+
PORT = s.getsockname()[1]
546544
(s2, _) = s.accept()
547545
s2.send(s2.recv(10))
548546
s2.close()
@@ -551,11 +549,16 @@ def echoer():
551549
_thread.start_new_thread(echoer, ())
552550
for _ in range(20):
553551
time.sleep(0.5)
554-
if GPORT is not None:
552+
if PORT is not None:
555553
break
556554

555+
if is_mono:
556+
# Warm up Mono to connecting sockets
557+
dummy = socket.socket()
557558
s = socket.socket()
558-
s.connect(('localhost', GPORT))
559+
if is_mono:
560+
dummy.close()
561+
s.connect(('localhost', PORT))
559562
f1 = s.makefile('r')
560563
f2 = s.makefile('w')
561564
s.close()
@@ -582,7 +585,6 @@ def test_cp7451(self):
582585
HOST = 'localhost'
583586
PORT = 0
584587
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
585-
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
586588
s.settimeout(20) # prevents the server from staying open if the client never connects
587589
s.bind((HOST, PORT))
588590
s.listen(1)

0 commit comments

Comments
 (0)