mirror of https://github.com/python/cpython
Use an event variable to wait for the server to be ready, not time.sleep().
This commit is contained in:
parent
fdc1a567ec
commit
3da4c4bcab
|
@ -6,12 +6,13 @@ import time
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
def server(evt):
|
def server(evt, ready):
|
||||||
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
serv.settimeout(3)
|
serv.settimeout(3)
|
||||||
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
serv.bind(("", 9091))
|
serv.bind(("", 9091))
|
||||||
serv.listen(5)
|
serv.listen(5)
|
||||||
|
ready.set()
|
||||||
try:
|
try:
|
||||||
conn, addr = serv.accept()
|
conn, addr = serv.accept()
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
|
@ -28,8 +29,9 @@ class GeneralTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
ftplib.FTP.port = 9091
|
ftplib.FTP.port = 9091
|
||||||
self.evt = threading.Event()
|
self.evt = threading.Event()
|
||||||
threading.Thread(target=server, args=(self.evt,)).start()
|
ready = threading.Event()
|
||||||
time.sleep(.1)
|
threading.Thread(target=server, args=(self.evt, ready)).start()
|
||||||
|
ready.wait()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.evt.wait()
|
self.evt.wait()
|
||||||
|
|
Loading…
Reference in New Issue