diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-03-06 00:00:36 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-03-06 00:00:36 (GMT) |
commit | e6a537976e918cca58c1b8c52fd4557b360bb3f8 (patch) | |
tree | 8ea5ede3b50b50de6553a89facf93a91914b727a /Lib/asyncio | |
parent | eeeebcd816c9c4e42de80475aec67d3066985397 (diff) | |
download | cpython-e6a537976e918cca58c1b8c52fd4557b360bb3f8.zip cpython-e6a537976e918cca58c1b8c52fd4557b360bb3f8.tar.gz cpython-e6a537976e918cca58c1b8c52fd4557b360bb3f8.tar.bz2 |
asyncio, Tulip issue 157: Improve test_events.py, avoid run_briefly() which is
not reliable
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/test_utils.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py index 71d309b..9c3656a 100644 --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -21,10 +21,11 @@ try: except ImportError: # pragma: no cover ssl = None -from . import tasks from . import base_events from . import events +from . import futures from . import selectors +from . import tasks if sys.platform == 'win32': # pragma: no cover @@ -52,18 +53,14 @@ def run_briefly(loop): gen.close() -def run_until(loop, pred, timeout=None): - if timeout is not None: - deadline = time.time() + timeout +def run_until(loop, pred, timeout=30): + 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 + raise futures.TimeoutError() + loop.run_until_complete(tasks.sleep(0.001, loop=loop)) def run_once(loop): |