]> granicus.if.org Git - python/commitdiff
Issue #19305: try to fix sporadic test_asyncio failure on FreeBSD 10.0
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 19 Oct 2013 23:51:25 +0000 (01:51 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 19 Oct 2013 23:51:25 +0000 (01:51 +0200)
Lib/asyncio/test_utils.py
Lib/test/test_asyncio/test_events.py

index 91bbedbafa4626b6919e6e422eb7710e330c5a8a..d650c4476a06bdc5e4b692e29cc82347b274bd2a 100644 (file)
@@ -7,6 +7,7 @@ import unittest.mock
 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 @@ def run_briefly(loop):
         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.
index 098cf71f89d9224ed94900b955b093f14801c2c5..f0f4810f6752e498bf190048192c41e810d85bce 100644 (file)
@@ -558,13 +558,14 @@ class EventLoopTestsMixin:
         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 @@ class EventLoopTestsMixin:
         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