summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_poplib.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-12-14 18:29:56 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-12-14 18:29:56 (GMT)
commit77e1bfc3777a318232e0816c4a9a15fc7955d80d (patch)
treec344c70de84080cf77089f08888c9e1b06508507 /Lib/test/test_poplib.py
parent486af72acfe1bcdd39352cac0a0d75e9c6e28597 (diff)
parent83ef2549de1f1f1eddf43934cacd6c57295e6681 (diff)
downloadcpython-77e1bfc3777a318232e0816c4a9a15fc7955d80d.zip
cpython-77e1bfc3777a318232e0816c4a9a15fc7955d80d.tar.gz
cpython-77e1bfc3777a318232e0816c4a9a15fc7955d80d.tar.bz2
Issue #13453: Fix a race condition in test_poplib.
Diffstat (limited to 'Lib/test/test_poplib.py')
-rw-r--r--Lib/test/test_poplib.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 0a3adcc..c0929a0 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -320,32 +320,34 @@ class TestTimeouts(TestCase):
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.sock.settimeout(3)
+ self.sock.settimeout(60) # Safety net. Look issue 11812
self.port = test_support.bind_port(self.sock)
- threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
- time.sleep(.1)
+ self.thread = threading.Thread(target=self.server, args=(self.evt,self.sock))
+ self.thread.setDaemon(True)
+ self.thread.start()
+ self.evt.wait()
def tearDown(self):
- self.evt.wait()
+ self.thread.join()
+ del self.thread # Clear out any dangling Thread objects.
def server(self, evt, serv):
serv.listen(5)
+ evt.set()
try:
conn, addr = serv.accept()
- except socket.timeout:
- pass
- else:
conn.send(b"+ Hola mundo\n")
conn.close()
+ except socket.timeout:
+ pass
finally:
serv.close()
- evt.set()
def testTimeoutDefault(self):
self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
- pop = poplib.POP3("localhost", self.port)
+ pop = poplib.POP3(HOST, self.port)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(pop.sock.gettimeout(), 30)
@@ -362,7 +364,7 @@ class TestTimeouts(TestCase):
pop.sock.close()
def testTimeoutValue(self):
- pop = poplib.POP3("localhost", self.port, timeout=30)
+ pop = poplib.POP3(HOST, self.port, timeout=30)
self.assertEqual(pop.sock.gettimeout(), 30)
pop.sock.close()