[Python-checkins] cpython: Issue #19305: try to fix sporadic test_asyncio failure on FreeBSD 10.0

antoine.pitrou python-checkins at python.org
Sun Oct 20 01:51:34 CEST 2013


http://hg.python.org/cpython/rev/f1447c152fb7
changeset:   86499:f1447c152fb7
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sun Oct 20 01:51:25 2013 +0200
summary:
  Issue #19305: try to fix sporadic test_asyncio failure on FreeBSD 10.0

files:
  Lib/asyncio/test_utils.py            |  15 +++++++++++++++
  Lib/test/test_asyncio/test_events.py |   7 +++++--
  2 files changed, 20 insertions(+), 2 deletions(-)


diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py
--- a/Lib/asyncio/test_utils.py
+++ b/Lib/asyncio/test_utils.py
@@ -7,6 +7,7 @@
 import os
 import sys
 import threading
+import time
 import unittest
 import unittest.mock
 from wsgiref.simple_server import make_server, WSGIRequestHandler, WSGIServer
@@ -46,6 +47,20 @@
         gen.close()
 
 
+def run_until(loop, pred, timeout=None):
+    if timeout is not None:
+        deadline = time.time() + timeout
+    while not pred():
+        if timeout is not None:
+            timeout = deadline - time.time()
+            if timeout <= 0:
+                return False
+            loop.run_until_complete(tasks.sleep(timeout, loop=loop))
+        else:
+            run_briefly(loop)
+    return True
+
+
 def run_once(loop):
     """loop.stop() schedules _raise_stop_error()
     and run_forever() runs until _raise_stop_error() callback.
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -558,13 +558,14 @@
         self.assertEqual(host, '0.0.0.0')
         client = socket.socket()
         client.connect(('127.0.0.1', port))
-        client.send(b'xxx')
+        client.sendall(b'xxx')
         test_utils.run_briefly(self.loop)
         self.assertIsInstance(proto, MyProto)
         self.assertEqual('INITIAL', proto.state)
         test_utils.run_briefly(self.loop)
         self.assertEqual('CONNECTED', proto.state)
-        test_utils.run_briefly(self.loop)  # windows iocp
+        test_utils.run_until(self.loop, lambda: proto.nbytes > 0,
+                             timeout=10)
         self.assertEqual(3, proto.nbytes)
 
         # extra info is available
@@ -623,6 +624,8 @@
         self.assertIsInstance(proto, MyProto)
         test_utils.run_briefly(self.loop)
         self.assertEqual('CONNECTED', proto.state)
+        test_utils.run_until(self.loop, lambda: proto.nbytes > 0,
+                             timeout=10)
         self.assertEqual(3, proto.nbytes)
 
         # extra info is available

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list