Commit 9012a0fb authored by Yury Selivanov's avatar Yury Selivanov Committed by GitHub

bpo-34728: Fix asyncio tests to run under "-Werror" (GH-9661)

parent 11c4eaa9
...@@ -395,9 +395,9 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -395,9 +395,9 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def test_async_gen_asyncio_01(self): def test_async_gen_asyncio_01(self):
async def gen(): async def gen():
yield 1 yield 1
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield 2 yield 2
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
return return
yield 3 yield 3
...@@ -407,7 +407,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -407,7 +407,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def test_async_gen_asyncio_02(self): def test_async_gen_asyncio_02(self):
async def gen(): async def gen():
yield 1 yield 1
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield 2 yield 2
1 / 0 1 / 0
yield 3 yield 3
...@@ -421,7 +421,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -421,7 +421,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
class Gen: class Gen:
async def __aiter__(self): async def __aiter__(self):
yield 1 yield 1
await asyncio.sleep(0.01, loop=loop) await asyncio.sleep(0.01)
yield 2 yield 2
res = loop.run_until_complete(self.to_list(Gen())) res = loop.run_until_complete(self.to_list(Gen()))
...@@ -430,13 +430,13 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -430,13 +430,13 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def test_async_gen_asyncio_anext_04(self): def test_async_gen_asyncio_anext_04(self):
async def foo(): async def foo():
yield 1 yield 1
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
try: try:
yield 2 yield 2
yield 3 yield 3
except ZeroDivisionError: except ZeroDivisionError:
yield 1000 yield 1000
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield 4 yield 4
async def run1(): async def run1():
...@@ -587,7 +587,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -587,7 +587,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
yield 1 yield 1
1 / 0 1 / 0
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield 12 yield 12
async def run(): async def run():
...@@ -610,8 +610,8 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -610,8 +610,8 @@ class AsyncGenAsyncioTest(unittest.TestCase):
yield 1 yield 1
1 / 0 1 / 0
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE += 1 DONE += 1
DONE += 1000 DONE += 1000
...@@ -637,8 +637,8 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -637,8 +637,8 @@ class AsyncGenAsyncioTest(unittest.TestCase):
DONE += 1000 DONE += 1000
yield 2 yield 2
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE += 1 DONE += 1
DONE += 1000 DONE += 1000
...@@ -647,7 +647,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -647,7 +647,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
it = gen.__aiter__() it = gen.__aiter__()
self.assertEqual(await it.__anext__(), 1) self.assertEqual(await it.__anext__(), 1)
t = self.loop.create_task(it.__anext__()) t = self.loop.create_task(it.__anext__())
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await gen.aclose() await gen.aclose()
return t return t
...@@ -657,7 +657,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -657,7 +657,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
# Silence ResourceWarnings # Silence ResourceWarnings
fut.cancel() fut.cancel()
t.cancel() t.cancel()
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
def test_async_gen_asyncio_gc_aclose_09(self): def test_async_gen_asyncio_gc_aclose_09(self):
DONE = 0 DONE = 0
...@@ -668,8 +668,8 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -668,8 +668,8 @@ class AsyncGenAsyncioTest(unittest.TestCase):
while True: while True:
yield 1 yield 1
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -678,7 +678,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -678,7 +678,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
await g.__anext__() await g.__anext__()
del g del g
await asyncio.sleep(0.1, loop=self.loop) await asyncio.sleep(0.1)
self.loop.run_until_complete(run()) self.loop.run_until_complete(run())
self.assertEqual(DONE, 1) self.assertEqual(DONE, 1)
...@@ -769,15 +769,15 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -769,15 +769,15 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def gen(): async def gen():
nonlocal DONE nonlocal DONE
try: try:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
v = yield 1 v = yield 1
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield v * 2 yield v * 2
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
return return
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -799,20 +799,20 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -799,20 +799,20 @@ class AsyncGenAsyncioTest(unittest.TestCase):
DONE = 0 DONE = 0
async def sleep_n_crash(delay): async def sleep_n_crash(delay):
await asyncio.sleep(delay, loop=self.loop) await asyncio.sleep(delay)
1 / 0 1 / 0
async def gen(): async def gen():
nonlocal DONE nonlocal DONE
try: try:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
v = yield 1 v = yield 1
await sleep_n_crash(0.01) await sleep_n_crash(0.01)
DONE += 1000 DONE += 1000
yield v * 2 yield v * 2
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -831,7 +831,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -831,7 +831,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
DONE = 0 DONE = 0
async def sleep_n_crash(delay): async def sleep_n_crash(delay):
fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop), fut = asyncio.ensure_future(asyncio.sleep(delay),
loop=self.loop) loop=self.loop)
self.loop.call_later(delay / 2, lambda: fut.cancel()) self.loop.call_later(delay / 2, lambda: fut.cancel())
return await fut return await fut
...@@ -839,14 +839,14 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -839,14 +839,14 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def gen(): async def gen():
nonlocal DONE nonlocal DONE
try: try:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
v = yield 1 v = yield 1
await sleep_n_crash(0.01) await sleep_n_crash(0.01)
DONE += 1000 DONE += 1000
yield v * 2 yield v * 2
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -885,18 +885,18 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -885,18 +885,18 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def gen(): async def gen():
nonlocal DONE nonlocal DONE
try: try:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
try: try:
v = yield 1 v = yield 1
except FooEr: except FooEr:
v = 1000 v = 1000
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield v * 2 yield v * 2
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
# return # return
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -921,7 +921,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -921,7 +921,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
pass pass
async def sleep_n_crash(delay): async def sleep_n_crash(delay):
fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop), fut = asyncio.ensure_future(asyncio.sleep(delay),
loop=self.loop) loop=self.loop)
self.loop.call_later(delay / 2, lambda: fut.cancel()) self.loop.call_later(delay / 2, lambda: fut.cancel())
return await fut return await fut
...@@ -929,17 +929,17 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -929,17 +929,17 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def gen(): async def gen():
nonlocal DONE nonlocal DONE
try: try:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
try: try:
v = yield 1 v = yield 1
except FooEr: except FooEr:
await sleep_n_crash(0.01) await sleep_n_crash(0.01)
yield v * 2 yield v * 2
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
# return # return
finally: finally:
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
DONE = 1 DONE = 1
async def run(): async def run():
...@@ -1038,10 +1038,10 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1038,10 +1038,10 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def waiter(timeout): async def waiter(timeout):
nonlocal finalized nonlocal finalized
try: try:
await asyncio.sleep(timeout, loop=self.loop) await asyncio.sleep(timeout)
yield 1 yield 1
finally: finally:
await asyncio.sleep(0, loop=self.loop) await asyncio.sleep(0)
finalized += 1 finalized += 1
async def wait(): async def wait():
...@@ -1051,7 +1051,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1051,7 +1051,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
t1 = self.loop.create_task(wait()) t1 = self.loop.create_task(wait())
t2 = self.loop.create_task(wait()) t2 = self.loop.create_task(wait())
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.1))
self.loop.run_until_complete(self.loop.shutdown_asyncgens()) self.loop.run_until_complete(self.loop.shutdown_asyncgens())
self.assertEqual(finalized, 2) self.assertEqual(finalized, 2)
...@@ -1059,7 +1059,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1059,7 +1059,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
# Silence warnings # Silence warnings
t1.cancel() t1.cancel()
t2.cancel() t2.cancel()
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.1))
def test_async_gen_asyncio_shutdown_02(self): def test_async_gen_asyncio_shutdown_02(self):
logged = 0 logged = 0
...@@ -1073,7 +1073,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1073,7 +1073,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
async def waiter(timeout): async def waiter(timeout):
try: try:
await asyncio.sleep(timeout, loop=self.loop) await asyncio.sleep(timeout)
yield 1 yield 1
finally: finally:
1 / 0 1 / 0
...@@ -1083,7 +1083,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1083,7 +1083,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
pass pass
t = self.loop.create_task(wait()) t = self.loop.create_task(wait())
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.1))
self.loop.set_exception_handler(logger) self.loop.set_exception_handler(logger)
self.loop.run_until_complete(self.loop.shutdown_asyncgens()) self.loop.run_until_complete(self.loop.shutdown_asyncgens())
...@@ -1092,12 +1092,12 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1092,12 +1092,12 @@ class AsyncGenAsyncioTest(unittest.TestCase):
# Silence warnings # Silence warnings
t.cancel() t.cancel()
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.1))
def test_async_gen_expression_01(self): def test_async_gen_expression_01(self):
async def arange(n): async def arange(n):
for i in range(n): for i in range(n):
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
yield i yield i
def make_arange(n): def make_arange(n):
...@@ -1112,7 +1112,7 @@ class AsyncGenAsyncioTest(unittest.TestCase): ...@@ -1112,7 +1112,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def test_async_gen_expression_02(self): def test_async_gen_expression_02(self):
async def wrap(n): async def wrap(n):
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
return n return n
def make_arange(n): def make_arange(n):
......
...@@ -15,7 +15,7 @@ class FunctionalTestCaseMixin: ...@@ -15,7 +15,7 @@ class FunctionalTestCaseMixin:
return asyncio.new_event_loop() return asyncio.new_event_loop()
def run_loop_briefly(self, *, delay=0.01): def run_loop_briefly(self, *, delay=0.01):
self.loop.run_until_complete(asyncio.sleep(delay, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(delay))
def loop_exception_handler(self, loop, context): def loop_exception_handler(self, loop, context):
self.__unhandled_exceptions.append(context) self.__unhandled_exceptions.append(context)
......
...@@ -482,7 +482,7 @@ class BaseEventLoopTests(test_utils.TestCase): ...@@ -482,7 +482,7 @@ class BaseEventLoopTests(test_utils.TestCase):
pass pass
async def foo(delay): async def foo(delay):
await asyncio.sleep(delay, loop=self.loop) await asyncio.sleep(delay)
def throw(): def throw():
raise ShowStopper raise ShowStopper
...@@ -579,7 +579,7 @@ class BaseEventLoopTests(test_utils.TestCase): ...@@ -579,7 +579,7 @@ class BaseEventLoopTests(test_utils.TestCase):
@asyncio.coroutine @asyncio.coroutine
def zero_error_coro(): def zero_error_coro():
yield from asyncio.sleep(0.01, loop=self.loop) yield from asyncio.sleep(0.01)
1/0 1/0
# Test Future.__del__ # Test Future.__del__
......
...@@ -64,7 +64,7 @@ class BaseTestBufferedProtocol(func_tests.FunctionalTestCaseMixin): ...@@ -64,7 +64,7 @@ class BaseTestBufferedProtocol(func_tests.FunctionalTestCaseMixin):
addr = srv.sockets[0].getsockname() addr = srv.sockets[0].getsockname()
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait_for(client(addr), 5, loop=self.loop)) asyncio.wait_for(client(addr), 5))
srv.close() srv.close()
self.loop.run_until_complete(srv.wait_closed()) self.loop.run_until_complete(srv.wait_closed())
......
...@@ -271,7 +271,7 @@ class EventLoopTestsMixin: ...@@ -271,7 +271,7 @@ class EventLoopTestsMixin:
def test_run_until_complete(self): def test_run_until_complete(self):
t0 = self.loop.time() t0 = self.loop.time()
self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.1))
t1 = self.loop.time() t1 = self.loop.time()
self.assertTrue(0.08 <= t1-t0 <= 0.8, t1-t0) self.assertTrue(0.08 <= t1-t0 <= 0.8, t1-t0)
...@@ -279,7 +279,7 @@ class EventLoopTestsMixin: ...@@ -279,7 +279,7 @@ class EventLoopTestsMixin:
async def cb(): async def cb():
self.loop.stop() self.loop.stop()
await asyncio.sleep(0.1, loop=self.loop) await asyncio.sleep(0.1)
task = cb() task = cb()
self.assertRaises(RuntimeError, self.assertRaises(RuntimeError,
self.loop.run_until_complete, task) self.loop.run_until_complete, task)
...@@ -1757,11 +1757,11 @@ class EventLoopTestsMixin: ...@@ -1757,11 +1757,11 @@ class EventLoopTestsMixin:
async def wait(): async def wait():
loop = self.loop loop = self.loop
await asyncio.sleep(1e-2, loop=loop) await asyncio.sleep(1e-2)
await asyncio.sleep(1e-4, loop=loop) await asyncio.sleep(1e-4)
await asyncio.sleep(1e-6, loop=loop) await asyncio.sleep(1e-6)
await asyncio.sleep(1e-8, loop=loop) await asyncio.sleep(1e-8)
await asyncio.sleep(1e-10, loop=loop) await asyncio.sleep(1e-10)
self.loop.run_until_complete(wait()) self.loop.run_until_complete(wait())
# The ideal number of call is 12, but on some platforms, the selector # The ideal number of call is 12, but on some platforms, the selector
......
...@@ -81,13 +81,13 @@ class LockTests(test_utils.TestCase): ...@@ -81,13 +81,13 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine @asyncio.coroutine
def test(lock): def test(lock):
yield from asyncio.sleep(0.01, loop=loop) yield from asyncio.sleep(0.01)
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
with (yield from lock) as _lock: with (yield from lock) as _lock:
self.assertIs(_lock, None) self.assertIs(_lock, None)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
yield from asyncio.sleep(0.01, loop=loop) yield from asyncio.sleep(0.01)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
...@@ -819,8 +819,7 @@ class ConditionTests(test_utils.TestCase): ...@@ -819,8 +819,7 @@ class ConditionTests(test_utils.TestCase):
condition = asyncio.Condition(loop=loop) condition = asyncio.Condition(loop=loop)
async with condition: async with condition:
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for(condition.wait(), timeout=0.5, await asyncio.wait_for(condition.wait(), timeout=0.5)
loop=loop)
loop.run_until_complete(task_timeout()) loop.run_until_complete(task_timeout())
......
...@@ -52,12 +52,12 @@ class LockTests(BaseTest): ...@@ -52,12 +52,12 @@ class LockTests(BaseTest):
] ]
async def test(lock): async def test(lock):
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
async with lock as _lock: async with lock as _lock:
self.assertIs(_lock, None) self.assertIs(_lock, None)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
...@@ -74,13 +74,13 @@ class LockTests(BaseTest): ...@@ -74,13 +74,13 @@ class LockTests(BaseTest):
] ]
async def test(lock): async def test(lock):
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
with await lock as _lock: with await lock as _lock:
self.assertIs(_lock, None) self.assertIs(_lock, None)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
await asyncio.sleep(0.01, loop=self.loop) await asyncio.sleep(0.01)
self.assertTrue(lock.locked()) self.assertTrue(lock.locked())
self.assertFalse(lock.locked()) self.assertFalse(lock.locked())
...@@ -198,13 +198,13 @@ class CoroutineTests(BaseTest): ...@@ -198,13 +198,13 @@ class CoroutineTests(BaseTest):
def test_double_await(self): def test_double_await(self):
async def afunc(): async def afunc():
await asyncio.sleep(0.1, loop=self.loop) await asyncio.sleep(0.1)
async def runner(): async def runner():
coro = afunc() coro = afunc()
t = asyncio.Task(coro, loop=self.loop) t = asyncio.Task(coro, loop=self.loop)
try: try:
await asyncio.sleep(0, loop=self.loop) await asyncio.sleep(0)
await coro await coro
finally: finally:
t.cancel() t.cancel()
......
...@@ -45,7 +45,7 @@ class QueueBasicTests(_QueueTestBase): ...@@ -45,7 +45,7 @@ class QueueBasicTests(_QueueTestBase):
# Start a task that waits to get. # Start a task that waits to get.
asyncio.Task(q.get(), loop=loop) asyncio.Task(q.get(), loop=loop)
# Let it start waiting. # Let it start waiting.
await asyncio.sleep(0.1, loop=loop) await asyncio.sleep(0.1)
self.assertTrue('_getters[1]' in fn(q)) self.assertTrue('_getters[1]' in fn(q))
# resume q.get coroutine to finish generator # resume q.get coroutine to finish generator
q.put_nowait(0) q.put_nowait(0)
...@@ -58,7 +58,7 @@ class QueueBasicTests(_QueueTestBase): ...@@ -58,7 +58,7 @@ class QueueBasicTests(_QueueTestBase):
# Start a task that waits to put. # Start a task that waits to put.
asyncio.Task(q.put(2), loop=loop) asyncio.Task(q.put(2), loop=loop)
# Let it start waiting. # Let it start waiting.
await asyncio.sleep(0.1, loop=loop) await asyncio.sleep(0.1)
self.assertTrue('_putters[1]' in fn(q)) self.assertTrue('_putters[1]' in fn(q))
# resume q.put coroutine to finish generator # resume q.put coroutine to finish generator
q.get_nowait() q.get_nowait()
...@@ -135,14 +135,14 @@ class QueueBasicTests(_QueueTestBase): ...@@ -135,14 +135,14 @@ class QueueBasicTests(_QueueTestBase):
async def test(): async def test():
t = asyncio.Task(putter(), loop=loop) t = asyncio.Task(putter(), loop=loop)
await asyncio.sleep(0.01, loop=loop) await asyncio.sleep(0.01)
# The putter is blocked after putting two items. # The putter is blocked after putting two items.
self.assertEqual([0, 1], have_been_put) self.assertEqual([0, 1], have_been_put)
self.assertEqual(0, q.get_nowait()) self.assertEqual(0, q.get_nowait())
# Let the putter resume and put last item. # Let the putter resume and put last item.
await asyncio.sleep(0.01, loop=loop) await asyncio.sleep(0.01)
self.assertEqual([0, 1, 2], have_been_put) self.assertEqual([0, 1, 2], have_been_put)
self.assertEqual(1, q.get_nowait()) self.assertEqual(1, q.get_nowait())
self.assertEqual(2, q.get_nowait()) self.assertEqual(2, q.get_nowait())
...@@ -234,11 +234,11 @@ class QueueGetTests(_QueueTestBase): ...@@ -234,11 +234,11 @@ class QueueGetTests(_QueueTestBase):
q = asyncio.Queue(loop=loop) q = asyncio.Queue(loop=loop)
async def queue_get(): async def queue_get():
return await asyncio.wait_for(q.get(), 0.051, loop=loop) return await asyncio.wait_for(q.get(), 0.051)
async def test(): async def test():
get_task = asyncio.Task(queue_get(), loop=loop) get_task = asyncio.Task(queue_get(), loop=loop)
await asyncio.sleep(0.01, loop=loop) # let the task start await asyncio.sleep(0.01) # let the task start
q.put_nowait(1) q.put_nowait(1)
return await get_task return await get_task
...@@ -297,7 +297,7 @@ class QueueGetTests(_QueueTestBase): ...@@ -297,7 +297,7 @@ class QueueGetTests(_QueueTestBase):
async def consumer(queue): async def consumer(queue):
try: try:
item = await asyncio.wait_for(queue.get(), 0.1, loop=self.loop) item = await asyncio.wait_for(queue.get(), 0.1)
except asyncio.TimeoutError: except asyncio.TimeoutError:
pass pass
...@@ -364,7 +364,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -364,7 +364,7 @@ class QueuePutTests(_QueueTestBase):
reader = loop.create_task(q.get()) reader = loop.create_task(q.get())
loop.run_until_complete(asyncio.sleep(0.01, loop=loop)) loop.run_until_complete(asyncio.sleep(0.01))
q.put_nowait(1) q.put_nowait(1)
q.put_nowait(2) q.put_nowait(2)
...@@ -395,7 +395,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -395,7 +395,7 @@ class QueuePutTests(_QueueTestBase):
reader2 = loop.create_task(q.get()) reader2 = loop.create_task(q.get())
reader3 = loop.create_task(q.get()) reader3 = loop.create_task(q.get())
loop.run_until_complete(asyncio.sleep(0.01, loop=loop)) loop.run_until_complete(asyncio.sleep(0.01))
q.put_nowait(1) q.put_nowait(1)
q.put_nowait(2) q.put_nowait(2)
...@@ -424,7 +424,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -424,7 +424,7 @@ class QueuePutTests(_QueueTestBase):
# putting a second item in the queue has to block (qsize=1) # putting a second item in the queue has to block (qsize=1)
writer = loop.create_task(q.put(2)) writer = loop.create_task(q.put(2))
loop.run_until_complete(asyncio.sleep(0.01, loop=loop)) loop.run_until_complete(asyncio.sleep(0.01))
value1 = q.get_nowait() value1 = q.get_nowait()
self.assertEqual(value1, 1) self.assertEqual(value1, 1)
...@@ -512,7 +512,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -512,7 +512,7 @@ class QueuePutTests(_QueueTestBase):
await queue.put(item) await queue.put(item)
async def getter(): async def getter():
await asyncio.sleep(0, loop=self.loop) await asyncio.sleep(0)
num = queue.qsize() num = queue.qsize()
for _ in range(num): for _ in range(num):
item = queue.get_nowait() item = queue.get_nowait()
...@@ -537,7 +537,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -537,7 +537,7 @@ class QueuePutTests(_QueueTestBase):
# Task waiting for space to put an item in the queue. # Task waiting for space to put an item in the queue.
put_task = loop.create_task(queue.put(1)) put_task = loop.create_task(queue.put(1))
loop.run_until_complete(asyncio.sleep(0.01, loop=loop)) loop.run_until_complete(asyncio.sleep(0.01))
# Check that the putter is correctly removed from queue._putters when # Check that the putter is correctly removed from queue._putters when
# the task is canceled. # the task is canceled.
...@@ -560,7 +560,7 @@ class QueuePutTests(_QueueTestBase): ...@@ -560,7 +560,7 @@ class QueuePutTests(_QueueTestBase):
# Task waiting for space to put a item in the queue. # Task waiting for space to put a item in the queue.
put_task = loop.create_task(queue.put(1)) put_task = loop.create_task(queue.put(1))
loop.run_until_complete(asyncio.sleep(0.01, loop=loop)) loop.run_until_complete(asyncio.sleep(0.01))
# get_nowait() remove the future of put_task from queue._putters. # get_nowait() remove the future of put_task from queue._putters.
queue.get_nowait() queue.get_nowait()
...@@ -638,7 +638,7 @@ class _QueueJoinTestMixin: ...@@ -638,7 +638,7 @@ class _QueueJoinTestMixin:
running = False running = False
for i in range(len(tasks)): for i in range(len(tasks)):
q.put_nowait(0) q.put_nowait(0)
self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop)) self.loop.run_until_complete(asyncio.wait(tasks))
def test_join_empty_queue(self): def test_join_empty_queue(self):
q = self.q_class(loop=self.loop) q = self.q_class(loop=self.loop)
......
...@@ -195,7 +195,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -195,7 +195,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_recv = mock.Mock() self.loop._sock_recv = mock.Mock()
f = self.loop.create_task(self.loop.sock_recv(sock, 1024)) f = self.loop.create_task(self.loop.sock_recv(sock, 1024))
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
self.assertEqual(self.loop._sock_recv.call_args[0][1:], self.assertEqual(self.loop._sock_recv.call_args[0][1:],
(None, sock, 1024)) (None, sock, 1024))
...@@ -215,7 +215,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -215,7 +215,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
fut = self.loop.create_task( fut = self.loop.create_task(
self.loop.sock_recv(sock, 1024)) self.loop.sock_recv(sock, 1024))
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
callback = self.loop.add_reader.call_args[0][1] callback = self.loop.add_reader.call_args[0][1]
params = self.loop.add_reader.call_args[0][2:] params = self.loop.add_reader.call_args[0][2:]
...@@ -226,7 +226,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -226,7 +226,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
sock.recv.side_effect = OSError(9) sock.recv.side_effect = OSError(9)
callback(*params) callback(*params)
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
self.assertIsInstance(fut.exception(), OSError) self.assertIsInstance(fut.exception(), OSError)
self.assertEqual((10,), self.loop.remove_reader.call_args[0]) self.assertEqual((10,), self.loop.remove_reader.call_args[0])
...@@ -278,7 +278,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -278,7 +278,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
f = self.loop.create_task( f = self.loop.create_task(
self.loop.sock_sendall(sock, b'data')) self.loop.sock_sendall(sock, b'data'))
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
self.assertEqual( self.assertEqual(
(None, sock, b'data'), (None, sock, b'data'),
...@@ -293,7 +293,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -293,7 +293,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_sendall = mock.Mock() self.loop._sock_sendall = mock.Mock()
f = self.loop.create_task(self.loop.sock_sendall(sock, b'')) f = self.loop.create_task(self.loop.sock_sendall(sock, b''))
self.loop.run_until_complete(asyncio.sleep(0, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0))
self.assertTrue(f.done()) self.assertTrue(f.done())
self.assertIsNone(f.result()) self.assertIsNone(f.result())
...@@ -309,7 +309,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -309,7 +309,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop.remove_writer = mock.Mock() self.loop.remove_writer = mock.Mock()
fut = self.loop.create_task(self.loop.sock_sendall(sock, b'data')) fut = self.loop.create_task(self.loop.sock_sendall(sock, b'data'))
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
callback = self.loop.add_writer.call_args[0][1] callback = self.loop.add_writer.call_args[0][1]
params = self.loop.add_writer.call_args[0][2:] params = self.loop.add_writer.call_args[0][2:]
...@@ -320,7 +320,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -320,7 +320,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
sock.send.side_effect = OSError(9) sock.send.side_effect = OSError(9)
callback(*params) callback(*params)
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
self.assertIsInstance(fut.exception(), OSError) self.assertIsInstance(fut.exception(), OSError)
self.assertEqual((10,), self.loop.remove_writer.call_args[0]) self.assertEqual((10,), self.loop.remove_writer.call_args[0])
...@@ -531,7 +531,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): ...@@ -531,7 +531,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_accept = mock.Mock() self.loop._sock_accept = mock.Mock()
f = self.loop.create_task(self.loop.sock_accept(sock)) f = self.loop.create_task(self.loop.sock_accept(sock))
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01))
self.assertFalse(self.loop._sock_accept.call_args[0][1]) self.assertFalse(self.loop._sock_accept.call_args[0][1])
self.assertIs(self.loop._sock_accept.call_args[0][2], sock) self.assertIs(self.loop._sock_accept.call_args[0][2], sock)
......
...@@ -252,7 +252,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -252,7 +252,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True) self.on_eof.set_result(True)
async def client(addr): async def client(addr):
await asyncio.sleep(0.5, loop=self.loop) await asyncio.sleep(0.5)
on_data = self.loop.create_future() on_data = self.loop.create_future()
on_eof = self.loop.create_future() on_eof = self.loop.create_future()
...@@ -271,7 +271,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -271,7 +271,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv: with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait_for(client(srv.addr), loop=self.loop, timeout=10)) asyncio.wait_for(client(srv.addr), timeout=10))
def test_start_tls_client_buf_proto_1(self): def test_start_tls_client_buf_proto_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE HELLO_MSG = b'1' * self.PAYLOAD_SIZE
...@@ -332,7 +332,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -332,7 +332,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True) self.on_eof.set_result(True)
async def client(addr): async def client(addr):
await asyncio.sleep(0.5, loop=self.loop) await asyncio.sleep(0.5)
on_data1 = self.loop.create_future() on_data1 = self.loop.create_future()
on_data2 = self.loop.create_future() on_data2 = self.loop.create_future()
...@@ -362,7 +362,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -362,7 +362,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv: with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait_for(client(srv.addr), asyncio.wait_for(client(srv.addr),
loop=self.loop, timeout=self.TIMEOUT)) timeout=self.TIMEOUT))
def test_start_tls_slow_client_cancel(self): def test_start_tls_slow_client_cancel(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE HELLO_MSG = b'1' * self.PAYLOAD_SIZE
...@@ -403,7 +403,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -403,7 +403,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True) self.on_eof.set_result(True)
async def client(addr): async def client(addr):
await asyncio.sleep(0.5, loop=self.loop) await asyncio.sleep(0.5)
on_data = self.loop.create_future() on_data = self.loop.create_future()
on_eof = self.loop.create_future() on_eof = self.loop.create_future()
...@@ -418,12 +418,11 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -418,12 +418,11 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for( await asyncio.wait_for(
self.loop.start_tls(tr, proto, client_context), self.loop.start_tls(tr, proto, client_context),
0.5, 0.5)
loop=self.loop)
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv: with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait_for(client(srv.addr), loop=self.loop, timeout=10)) asyncio.wait_for(client(srv.addr), timeout=10))
def test_start_tls_server_1(self): def test_start_tls_server_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE HELLO_MSG = b'1' * self.PAYLOAD_SIZE
...@@ -496,7 +495,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -496,7 +495,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
timeout=self.TIMEOUT): timeout=self.TIMEOUT):
await asyncio.wait_for( await asyncio.wait_for(
main(proto, on_con, on_eof, on_con_lost), main(proto, on_con, on_eof, on_con_lost),
loop=self.loop, timeout=self.TIMEOUT) timeout=self.TIMEOUT)
server.close() server.close()
await server.wait_closed() await server.wait_closed()
...@@ -541,8 +540,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin): ...@@ -541,8 +540,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
ssl=client_sslctx, ssl=client_sslctx,
server_hostname='', server_hostname='',
ssl_handshake_timeout=10.0), ssl_handshake_timeout=10.0),
0.5, 0.5)
loop=self.loop)
with self.tcp_server(server, with self.tcp_server(server,
max_clients=1, max_clients=1,
......
...@@ -560,7 +560,7 @@ class StreamTests(test_utils.TestCase): ...@@ -560,7 +560,7 @@ class StreamTests(test_utils.TestCase):
t1 = asyncio.Task(stream.readline(), loop=self.loop) t1 = asyncio.Task(stream.readline(), loop=self.loop)
t2 = asyncio.Task(set_err(), loop=self.loop) t2 = asyncio.Task(set_err(), loop=self.loop)
self.loop.run_until_complete(asyncio.wait([t1, t2], loop=self.loop)) self.loop.run_until_complete(asyncio.wait([t1, t2]))
self.assertRaises(ValueError, t1.result) self.assertRaises(ValueError, t1.result)
......
...@@ -126,7 +126,7 @@ class SubprocessMixin: ...@@ -126,7 +126,7 @@ class SubprocessMixin:
return (exitcode, data) return (exitcode, data)
task = run(b'some data') task = run(b'some data')
task = asyncio.wait_for(task, 60.0, loop=self.loop) task = asyncio.wait_for(task, 60.0)
exitcode, stdout = self.loop.run_until_complete(task) exitcode, stdout = self.loop.run_until_complete(task)
self.assertEqual(exitcode, 0) self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data') self.assertEqual(stdout, b'some data')
...@@ -144,7 +144,7 @@ class SubprocessMixin: ...@@ -144,7 +144,7 @@ class SubprocessMixin:
return proc.returncode, stdout return proc.returncode, stdout
task = run(b'some data') task = run(b'some data')
task = asyncio.wait_for(task, 60.0, loop=self.loop) task = asyncio.wait_for(task, 60.0)
exitcode, stdout = self.loop.run_until_complete(task) exitcode, stdout = self.loop.run_until_complete(task)
self.assertEqual(exitcode, 0) self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data') self.assertEqual(stdout, b'some data')
...@@ -233,7 +233,7 @@ class SubprocessMixin: ...@@ -233,7 +233,7 @@ class SubprocessMixin:
proc, large_data = self.prepare_broken_pipe_test() proc, large_data = self.prepare_broken_pipe_test()
async def write_stdin(proc, data): async def write_stdin(proc, data):
await asyncio.sleep(0.5, loop=self.loop) await asyncio.sleep(0.5)
proc.stdin.write(data) proc.stdin.write(data)
await proc.stdin.drain() await proc.stdin.drain()
...@@ -504,7 +504,7 @@ class SubprocessMixin: ...@@ -504,7 +504,7 @@ class SubprocessMixin:
while True: while True:
data = await process.stdout.read(65536) data = await process.stdout.read(65536)
if data: if data:
await asyncio.sleep(0.3, loop=self.loop) await asyncio.sleep(0.3)
else: else:
break break
......
...@@ -45,7 +45,6 @@ def set_coroutine_debug(enabled): ...@@ -45,7 +45,6 @@ def set_coroutine_debug(enabled):
coroutines._DEBUG = old_debug coroutines._DEBUG = old_debug
def format_coroutine(qualname, state, src, source_traceback, generator=False): def format_coroutine(qualname, state, src, source_traceback, generator=False):
if generator: if generator:
state = '%s' % state state = '%s' % state
...@@ -472,7 +471,7 @@ class BaseTaskTests: ...@@ -472,7 +471,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
async def task(): async def task():
await asyncio.sleep(10.0, loop=loop) await asyncio.sleep(10.0)
return 12 return 12
t = self.new_task(loop, task()) t = self.new_task(loop, task())
...@@ -595,7 +594,7 @@ class BaseTaskTests: ...@@ -595,7 +594,7 @@ class BaseTaskTests:
t.cancel() t.cancel()
self.assertTrue(t._must_cancel) # White-box test. self.assertTrue(t._must_cancel) # White-box test.
# The sleep should be cancelled immediately. # The sleep should be cancelled immediately.
await asyncio.sleep(100, loop=loop) await asyncio.sleep(100)
return 12 return 12
t = self.new_task(loop, task()) t = self.new_task(loop, task())
...@@ -641,7 +640,7 @@ class BaseTaskTests: ...@@ -641,7 +640,7 @@ class BaseTaskTests:
async def task(): async def task():
nonlocal x nonlocal x
while x < 10: while x < 10:
await asyncio.sleep(0.1, loop=loop) await asyncio.sleep(0.1)
x += 1 x += 1
if x == 2: if x == 2:
loop.stop() loop.stop()
...@@ -677,7 +676,7 @@ class BaseTaskTests: ...@@ -677,7 +676,7 @@ class BaseTaskTests:
fut = self.new_future(loop) fut = self.new_future(loop)
fut.set_result('done') fut.set_result('done')
ret = loop.run_until_complete(asyncio.wait_for(fut, 0, loop=loop)) ret = loop.run_until_complete(asyncio.wait_for(fut, 0))
self.assertEqual(ret, 'done') self.assertEqual(ret, 'done')
self.assertTrue(fut.done()) self.assertTrue(fut.done())
...@@ -698,7 +697,7 @@ class BaseTaskTests: ...@@ -698,7 +697,7 @@ class BaseTaskTests:
foo_started = True foo_started = True
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
loop.run_until_complete(asyncio.wait_for(foo(), 0, loop=loop)) loop.run_until_complete(asyncio.wait_for(foo(), 0))
self.assertAlmostEqual(0, loop.time()) self.assertAlmostEqual(0, loop.time())
self.assertEqual(foo_started, False) self.assertEqual(foo_started, False)
...@@ -720,7 +719,7 @@ class BaseTaskTests: ...@@ -720,7 +719,7 @@ class BaseTaskTests:
nonlocal foo_running nonlocal foo_running
foo_running = True foo_running = True
try: try:
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
finally: finally:
foo_running = False foo_running = False
return 'done' return 'done'
...@@ -728,8 +727,7 @@ class BaseTaskTests: ...@@ -728,8 +727,7 @@ class BaseTaskTests:
fut = self.new_task(loop, foo()) fut = self.new_task(loop, foo())
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
loop.run_until_complete(asyncio.wait_for( loop.run_until_complete(asyncio.wait_for(fut, timeout))
fut, timeout, loop=loop))
self.assertTrue(fut.done()) self.assertTrue(fut.done())
# it should have been cancelled due to the timeout # it should have been cancelled due to the timeout
self.assertTrue(fut.cancelled()) self.assertTrue(fut.cancelled())
...@@ -753,7 +751,7 @@ class BaseTaskTests: ...@@ -753,7 +751,7 @@ class BaseTaskTests:
nonlocal foo_running nonlocal foo_running
foo_running = True foo_running = True
try: try:
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
finally: finally:
foo_running = False foo_running = False
return 'done' return 'done'
...@@ -761,7 +759,7 @@ class BaseTaskTests: ...@@ -761,7 +759,7 @@ class BaseTaskTests:
fut = self.new_task(loop, foo()) fut = self.new_task(loop, foo())
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
loop.run_until_complete(asyncio.wait_for(fut, 0.1, loop=loop)) loop.run_until_complete(asyncio.wait_for(fut, 0.1))
self.assertTrue(fut.done()) self.assertTrue(fut.done())
# it should have been cancelled due to the timeout # it should have been cancelled due to the timeout
self.assertTrue(fut.cancelled()) self.assertTrue(fut.cancelled())
...@@ -775,9 +773,7 @@ class BaseTaskTests: ...@@ -775,9 +773,7 @@ class BaseTaskTests:
def coro(): def coro():
return 'done' return 'done'
res = loop.run_until_complete(asyncio.wait_for(coro(), res = loop.run_until_complete(asyncio.wait_for(coro(), timeout=None))
timeout=None,
loop=loop))
self.assertEqual(res, 'done') self.assertEqual(res, 'done')
def test_wait_for_with_global_loop(self): def test_wait_for_with_global_loop(self):
...@@ -792,7 +788,7 @@ class BaseTaskTests: ...@@ -792,7 +788,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
async def foo(): async def foo():
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
return 'done' return 'done'
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
...@@ -817,7 +813,7 @@ class BaseTaskTests: ...@@ -817,7 +813,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
fut = self.new_future(loop) fut = self.new_future(loop)
task = asyncio.wait_for(fut, timeout=0.2, loop=loop) task = asyncio.wait_for(fut, timeout=0.2)
loop.call_later(0.1, fut.set_result, "ok") loop.call_later(0.1, fut.set_result, "ok")
res = loop.run_until_complete(task) res = loop.run_until_complete(task)
self.assertEqual(res, "ok") self.assertEqual(res, "ok")
...@@ -832,14 +828,14 @@ class BaseTaskTests: ...@@ -832,14 +828,14 @@ class BaseTaskTests:
async def inner(): async def inner():
nonlocal task_done nonlocal task_done
try: try:
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
finally: finally:
task_done = True task_done = True
inner_task = self.new_task(loop, inner()) inner_task = self.new_task(loop, inner())
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for(inner_task, timeout=0.1, loop=loop) await asyncio.wait_for(inner_task, timeout=0.1)
self.assertTrue(task_done) self.assertTrue(task_done)
...@@ -852,23 +848,23 @@ class BaseTaskTests: ...@@ -852,23 +848,23 @@ class BaseTaskTests:
async def foo(): async def foo():
async def inner(): async def inner():
try: try:
await asyncio.sleep(0.3, loop=loop) await asyncio.sleep(0.3)
except asyncio.CancelledError: except asyncio.CancelledError:
try: try:
await asyncio.sleep(0.3, loop=loop) await asyncio.sleep(0.3)
except asyncio.CancelledError: except asyncio.CancelledError:
await asyncio.sleep(0.3, loop=loop) await asyncio.sleep(0.3)
return 42 return 42
inner_task = self.new_task(loop, inner()) inner_task = self.new_task(loop, inner())
wait = asyncio.wait_for(inner_task, timeout=0.1, loop=loop) wait = asyncio.wait_for(inner_task, timeout=0.1)
# Test that wait_for itself is properly cancellable # Test that wait_for itself is properly cancellable
# even when the initial task holds up the initial cancellation. # even when the initial task holds up the initial cancellation.
task = self.new_task(loop, wait) task = self.new_task(loop, wait)
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
task.cancel() task.cancel()
with self.assertRaises(asyncio.CancelledError): with self.assertRaises(asyncio.CancelledError):
...@@ -889,11 +885,11 @@ class BaseTaskTests: ...@@ -889,11 +885,11 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop)) a = self.new_task(loop, asyncio.sleep(0.1))
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop)) b = self.new_task(loop, asyncio.sleep(0.15))
async def foo(): async def foo():
done, pending = await asyncio.wait([b, a], loop=loop) done, pending = await asyncio.wait([b, a])
self.assertEqual(done, set([a, b])) self.assertEqual(done, set([a, b]))
self.assertEqual(pending, set()) self.assertEqual(pending, set())
return 42 return 42
...@@ -918,8 +914,8 @@ class BaseTaskTests: ...@@ -918,8 +914,8 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(0.01, loop=loop)) a = self.new_task(loop, asyncio.sleep(0.01))
b = self.new_task(loop, asyncio.sleep(0.015, loop=loop)) b = self.new_task(loop, asyncio.sleep(0.015))
async def foo(): async def foo():
done, pending = await asyncio.wait([b, a]) done, pending = await asyncio.wait([b, a])
...@@ -942,7 +938,7 @@ class BaseTaskTests: ...@@ -942,7 +938,7 @@ class BaseTaskTests:
task =self.new_task( task =self.new_task(
self.loop, self.loop,
asyncio.wait([c, c, coro('spam')], loop=self.loop)) asyncio.wait([c, c, coro('spam')]))
done, pending = self.loop.run_until_complete(task) done, pending = self.loop.run_until_complete(task)
...@@ -952,11 +948,11 @@ class BaseTaskTests: ...@@ -952,11 +948,11 @@ class BaseTaskTests:
def test_wait_errors(self): def test_wait_errors(self):
self.assertRaises( self.assertRaises(
ValueError, self.loop.run_until_complete, ValueError, self.loop.run_until_complete,
asyncio.wait(set(), loop=self.loop)) asyncio.wait(set()))
# -1 is an invalid return_when value # -1 is an invalid return_when value
sleep_coro = asyncio.sleep(10.0, loop=self.loop) sleep_coro = asyncio.sleep(10.0)
wait_coro = asyncio.wait([sleep_coro], return_when=-1, loop=self.loop) wait_coro = asyncio.wait([sleep_coro], return_when=-1)
self.assertRaises(ValueError, self.assertRaises(ValueError,
self.loop.run_until_complete, wait_coro) self.loop.run_until_complete, wait_coro)
...@@ -973,12 +969,11 @@ class BaseTaskTests: ...@@ -973,12 +969,11 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop)) a = self.new_task(loop, asyncio.sleep(10.0))
b = self.new_task(loop, asyncio.sleep(0.1, loop=loop)) b = self.new_task(loop, asyncio.sleep(0.1))
task = self.new_task( task = self.new_task(
loop, loop,
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED, asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
loop=loop))
done, pending = loop.run_until_complete(task) done, pending = loop.run_until_complete(task)
self.assertEqual({b}, done) self.assertEqual({b}, done)
...@@ -990,7 +985,7 @@ class BaseTaskTests: ...@@ -990,7 +985,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_wait_really_done(self): def test_wait_really_done(self):
# there is possibility that some tasks in the pending list # there is possibility that some tasks in the pending list
...@@ -1009,8 +1004,7 @@ class BaseTaskTests: ...@@ -1009,8 +1004,7 @@ class BaseTaskTests:
b = self.new_task(self.loop, coro2()) b = self.new_task(self.loop, coro2())
task = self.new_task( task = self.new_task(
self.loop, self.loop,
asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED, asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
loop=self.loop))
done, pending = self.loop.run_until_complete(task) done, pending = self.loop.run_until_complete(task)
self.assertEqual({a, b}, done) self.assertEqual({a, b}, done)
...@@ -1029,7 +1023,7 @@ class BaseTaskTests: ...@@ -1029,7 +1023,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
# first_exception, task already has exception # first_exception, task already has exception
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop)) a = self.new_task(loop, asyncio.sleep(10.0))
@asyncio.coroutine @asyncio.coroutine
def exc(): def exc():
...@@ -1038,8 +1032,7 @@ class BaseTaskTests: ...@@ -1038,8 +1032,7 @@ class BaseTaskTests:
b = self.new_task(loop, exc()) b = self.new_task(loop, exc())
task = self.new_task( task = self.new_task(
loop, loop,
asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION, asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION))
loop=loop))
done, pending = loop.run_until_complete(task) done, pending = loop.run_until_complete(task)
self.assertEqual({b}, done) self.assertEqual({b}, done)
...@@ -1048,7 +1041,7 @@ class BaseTaskTests: ...@@ -1048,7 +1041,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_wait_first_exception_in_wait(self): def test_wait_first_exception_in_wait(self):
...@@ -1062,15 +1055,14 @@ class BaseTaskTests: ...@@ -1062,15 +1055,14 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
# first_exception, exception during waiting # first_exception, exception during waiting
a = self.new_task(loop, asyncio.sleep(10.0, loop=loop)) a = self.new_task(loop, asyncio.sleep(10.0))
async def exc(): async def exc():
await asyncio.sleep(0.01, loop=loop) await asyncio.sleep(0.01)
raise ZeroDivisionError('err') raise ZeroDivisionError('err')
b = self.new_task(loop, exc()) b = self.new_task(loop, exc())
task = asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION, task = asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION)
loop=loop)
done, pending = loop.run_until_complete(task) done, pending = loop.run_until_complete(task)
self.assertEqual({b}, done) self.assertEqual({b}, done)
...@@ -1079,7 +1071,7 @@ class BaseTaskTests: ...@@ -1079,7 +1071,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_wait_with_exception(self): def test_wait_with_exception(self):
...@@ -1092,17 +1084,17 @@ class BaseTaskTests: ...@@ -1092,17 +1084,17 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop)) a = self.new_task(loop, asyncio.sleep(0.1))
@asyncio.coroutine @asyncio.coroutine
def sleeper(): def sleeper():
yield from asyncio.sleep(0.15, loop=loop) yield from asyncio.sleep(0.15)
raise ZeroDivisionError('really') raise ZeroDivisionError('really')
b = self.new_task(loop, sleeper()) b = self.new_task(loop, sleeper())
async def foo(): async def foo():
done, pending = await asyncio.wait([b, a], loop=loop) done, pending = await asyncio.wait([b, a])
self.assertEqual(len(done), 2) self.assertEqual(len(done), 2)
self.assertEqual(pending, set()) self.assertEqual(pending, set())
errors = set(f for f in done if f.exception() is not None) errors = set(f for f in done if f.exception() is not None)
...@@ -1127,12 +1119,11 @@ class BaseTaskTests: ...@@ -1127,12 +1119,11 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop)) a = self.new_task(loop, asyncio.sleep(0.1))
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop)) b = self.new_task(loop, asyncio.sleep(0.15))
async def foo(): async def foo():
done, pending = await asyncio.wait([b, a], timeout=0.11, done, pending = await asyncio.wait([b, a], timeout=0.11)
loop=loop)
self.assertEqual(done, set([a])) self.assertEqual(done, set([a]))
self.assertEqual(pending, set([b])) self.assertEqual(pending, set([b]))
...@@ -1141,7 +1132,7 @@ class BaseTaskTests: ...@@ -1141,7 +1132,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_wait_concurrent_complete(self): def test_wait_concurrent_complete(self):
...@@ -1156,11 +1147,11 @@ class BaseTaskTests: ...@@ -1156,11 +1147,11 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = self.new_task(loop, asyncio.sleep(0.1, loop=loop)) a = self.new_task(loop, asyncio.sleep(0.1))
b = self.new_task(loop, asyncio.sleep(0.15, loop=loop)) b = self.new_task(loop, asyncio.sleep(0.15))
done, pending = loop.run_until_complete( done, pending = loop.run_until_complete(
asyncio.wait([b, a], timeout=0.1, loop=loop)) asyncio.wait([b, a], timeout=0.1))
self.assertEqual(done, set([a])) self.assertEqual(done, set([a]))
self.assertEqual(pending, set([b])) self.assertEqual(pending, set([b]))
...@@ -1168,7 +1159,7 @@ class BaseTaskTests: ...@@ -1168,7 +1159,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_as_completed(self): def test_as_completed(self):
...@@ -1187,7 +1178,7 @@ class BaseTaskTests: ...@@ -1187,7 +1178,7 @@ class BaseTaskTests:
@asyncio.coroutine @asyncio.coroutine
def sleeper(dt, x): def sleeper(dt, x):
nonlocal time_shifted nonlocal time_shifted
yield from asyncio.sleep(dt, loop=loop) yield from asyncio.sleep(dt)
completed.add(x) completed.add(x)
if not time_shifted and 'a' in completed and 'b' in completed: if not time_shifted and 'a' in completed and 'b' in completed:
time_shifted = True time_shifted = True
...@@ -1225,8 +1216,8 @@ class BaseTaskTests: ...@@ -1225,8 +1216,8 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = loop.create_task(asyncio.sleep(0.1, 'a', loop=loop)) a = loop.create_task(asyncio.sleep(0.1, 'a'))
b = loop.create_task(asyncio.sleep(0.15, 'b', loop=loop)) b = loop.create_task(asyncio.sleep(0.15, 'b'))
async def foo(): async def foo():
values = [] values = []
...@@ -1249,7 +1240,7 @@ class BaseTaskTests: ...@@ -1249,7 +1240,7 @@ class BaseTaskTests:
# move forward to close generator # move forward to close generator
loop.advance_time(10) loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b], loop=loop)) loop.run_until_complete(asyncio.wait([a, b]))
def test_as_completed_with_unused_timeout(self): def test_as_completed_with_unused_timeout(self):
...@@ -1260,7 +1251,7 @@ class BaseTaskTests: ...@@ -1260,7 +1251,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = asyncio.sleep(0.01, 'a', loop=loop) a = asyncio.sleep(0.01, 'a')
async def foo(): async def foo():
for f in asyncio.as_completed([a], timeout=1, loop=loop): for f in asyncio.as_completed([a], timeout=1, loop=loop):
...@@ -1278,8 +1269,8 @@ class BaseTaskTests: ...@@ -1278,8 +1269,8 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = asyncio.sleep(0.05, 'a', loop=loop) a = asyncio.sleep(0.05, 'a')
b = asyncio.sleep(0.10, 'b', loop=loop) b = asyncio.sleep(0.10, 'b')
fs = {a, b} fs = {a, b}
futs = list(asyncio.as_completed(fs, loop=loop)) futs = list(asyncio.as_completed(fs, loop=loop))
self.assertEqual(len(futs), 2) self.assertEqual(len(futs), 2)
...@@ -1303,12 +1294,12 @@ class BaseTaskTests: ...@@ -1303,12 +1294,12 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
a = asyncio.sleep(0.05, 'a', loop=loop) a = asyncio.sleep(0.05, 'a')
b = asyncio.sleep(0.05, 'b', loop=loop) b = asyncio.sleep(0.05, 'b')
fs = {a, b} fs = {a, b}
futs = list(asyncio.as_completed(fs, loop=loop)) futs = list(asyncio.as_completed(fs, loop=loop))
self.assertEqual(len(futs), 2) self.assertEqual(len(futs), 2)
waiter = asyncio.wait(futs, loop=loop) waiter = asyncio.wait(futs)
done, pending = loop.run_until_complete(waiter) done, pending = loop.run_until_complete(waiter)
self.assertEqual(set(f.result() for f in done), {'a', 'b'}) self.assertEqual(set(f.result() for f in done), {'a', 'b'})
...@@ -1346,8 +1337,8 @@ class BaseTaskTests: ...@@ -1346,8 +1337,8 @@ class BaseTaskTests:
@asyncio.coroutine @asyncio.coroutine
def sleeper(dt, arg): def sleeper(dt, arg):
yield from asyncio.sleep(dt/2, loop=loop) yield from asyncio.sleep(dt/2)
res = yield from asyncio.sleep(dt/2, arg, loop=loop) res = yield from asyncio.sleep(dt/2, arg)
return res return res
t = self.new_task(loop, sleeper(0.1, 'yeah')) t = self.new_task(loop, sleeper(0.1, 'yeah'))
...@@ -1365,7 +1356,7 @@ class BaseTaskTests: ...@@ -1365,7 +1356,7 @@ class BaseTaskTests:
loop = self.new_test_loop(gen) loop = self.new_test_loop(gen)
t = self.new_task(loop, asyncio.sleep(10.0, 'yeah', loop=loop)) t = self.new_task(loop, asyncio.sleep(10.0, 'yeah'))
handle = None handle = None
orig_call_later = loop.call_later orig_call_later = loop.call_later
...@@ -1397,7 +1388,7 @@ class BaseTaskTests: ...@@ -1397,7 +1388,7 @@ class BaseTaskTests:
@asyncio.coroutine @asyncio.coroutine
def sleep(dt): def sleep(dt):
yield from asyncio.sleep(dt, loop=loop) yield from asyncio.sleep(dt)
@asyncio.coroutine @asyncio.coroutine
def doit(): def doit():
...@@ -1502,7 +1493,7 @@ class BaseTaskTests: ...@@ -1502,7 +1493,7 @@ class BaseTaskTests:
@asyncio.coroutine @asyncio.coroutine
def sleeper(): def sleeper():
yield from asyncio.sleep(10, loop=loop) yield from asyncio.sleep(10)
base_exc = BaseException() base_exc = BaseException()
...@@ -1663,8 +1654,7 @@ class BaseTaskTests: ...@@ -1663,8 +1654,7 @@ class BaseTaskTests:
task1 = self.new_task(self.loop, coro1(self.loop)) task1 = self.new_task(self.loop, coro1(self.loop))
task2 = self.new_task(self.loop, coro2(self.loop)) task2 = self.new_task(self.loop, coro2(self.loop))
self.loop.run_until_complete(asyncio.wait((task1, task2), self.loop.run_until_complete(asyncio.wait((task1, task2)))
loop=self.loop))
self.assertIsNone(asyncio.current_task(loop=self.loop)) self.assertIsNone(asyncio.current_task(loop=self.loop))
# Some thorough tests for cancellation propagation through # Some thorough tests for cancellation propagation through
...@@ -1714,7 +1704,7 @@ class BaseTaskTests: ...@@ -1714,7 +1704,7 @@ class BaseTaskTests:
async def outer(): async def outer():
nonlocal proof nonlocal proof
d, p = await asyncio.wait([inner()], loop=self.loop) d, p = await asyncio.wait([inner()])
proof += 100 proof += 100
f = asyncio.ensure_future(outer(), loop=self.loop) f = asyncio.ensure_future(outer(), loop=self.loop)
...@@ -1827,15 +1817,15 @@ class BaseTaskTests: ...@@ -1827,15 +1817,15 @@ class BaseTaskTests:
# wait() expects a list of futures, not a future instance # wait() expects a list of futures, not a future instance
self.assertRaises(TypeError, self.loop.run_until_complete, self.assertRaises(TypeError, self.loop.run_until_complete,
asyncio.wait(fut, loop=self.loop)) asyncio.wait(fut))
coro = coroutine_function() coro = coroutine_function()
self.assertRaises(TypeError, self.loop.run_until_complete, self.assertRaises(TypeError, self.loop.run_until_complete,
asyncio.wait(coro, loop=self.loop)) asyncio.wait(coro))
coro.close() coro.close()
# wait() expects at least a future # wait() expects at least a future
self.assertRaises(ValueError, self.loop.run_until_complete, self.assertRaises(ValueError, self.loop.run_until_complete,
asyncio.wait([], loop=self.loop)) asyncio.wait([]))
def test_corowrapper_mocks_generator(self): def test_corowrapper_mocks_generator(self):
...@@ -2027,7 +2017,7 @@ class BaseTaskTests: ...@@ -2027,7 +2017,7 @@ class BaseTaskTests:
@asyncio.coroutine @asyncio.coroutine
def runner(): def runner():
task = self.new_task(loop, coro()) task = self.new_task(loop, coro())
yield from asyncio.sleep(0.05, loop=loop) yield from asyncio.sleep(0.05)
task.cancel() task.cancel()
task = None task = None
...@@ -2111,7 +2101,7 @@ class BaseTaskTests: ...@@ -2111,7 +2101,7 @@ class BaseTaskTests:
task = loop.create_task(blocking_coroutine()) task = loop.create_task(blocking_coroutine())
wait = loop.create_task(asyncio.wait_for(task, timeout, loop=loop)) wait = loop.create_task(asyncio.wait_for(task, timeout))
loop.call_soon(wait.cancel) loop.call_soon(wait.cancel)
self.assertRaises(asyncio.CancelledError, self.assertRaises(asyncio.CancelledError,
...@@ -2164,7 +2154,7 @@ class BaseTaskTests: ...@@ -2164,7 +2154,7 @@ class BaseTaskTests:
time = 0 time = 0
while True: while True:
time += 0.05 time += 0.05
await asyncio.gather(asyncio.sleep(0.05, loop=loop), await asyncio.gather(asyncio.sleep(0.05),
return_exceptions=True, return_exceptions=True,
loop=loop) loop=loop)
if time > 1: if time > 1:
...@@ -2172,7 +2162,7 @@ class BaseTaskTests: ...@@ -2172,7 +2162,7 @@ class BaseTaskTests:
async def main(): async def main():
qwe = self.new_task(loop, test()) qwe = self.new_task(loop, test())
await asyncio.sleep(0.2, loop=loop) await asyncio.sleep(0.2)
qwe.cancel() qwe.cancel()
try: try:
await qwe await qwe
...@@ -2305,7 +2295,7 @@ class BaseTaskTests: ...@@ -2305,7 +2295,7 @@ class BaseTaskTests:
cvar = contextvars.ContextVar('cvar', default='nope') cvar = contextvars.ContextVar('cvar', default='nope')
async def sub(): async def sub():
await asyncio.sleep(0.01, loop=loop) await asyncio.sleep(0.01)
self.assertEqual(cvar.get(), 'nope') self.assertEqual(cvar.get(), 'nope')
cvar.set('something else') cvar.set('something else')
...@@ -2346,7 +2336,7 @@ class BaseTaskTests: ...@@ -2346,7 +2336,7 @@ class BaseTaskTests:
for i in range(3): for i in range(3):
# Test that task passed its context to add_done_callback: # Test that task passed its context to add_done_callback:
cvar.set(f'yes{i}-{j}') cvar.set(f'yes{i}-{j}')
await asyncio.sleep(0.001, loop=loop) await asyncio.sleep(0.001)
self.assertEqual(cvar.get(), f'yes{i}-{j}') self.assertEqual(cvar.get(), f'yes{i}-{j}')
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
...@@ -2366,8 +2356,7 @@ class BaseTaskTests: ...@@ -2366,8 +2356,7 @@ class BaseTaskTests:
async def sub(num): async def sub(num):
for i in range(10): for i in range(10):
cvar.set(num + i) cvar.set(num + i)
await asyncio.sleep( await asyncio.sleep(random.uniform(0.001, 0.05))
random.uniform(0.001, 0.05), loop=loop)
self.assertEqual(cvar.get(), num + i) self.assertEqual(cvar.get(), num + i)
async def main(): async def main():
...@@ -2452,7 +2441,7 @@ class SetMethodsTest: ...@@ -2452,7 +2441,7 @@ class SetMethodsTest:
self.loop.call_exception_handler = exc_handler = mock.Mock() self.loop.call_exception_handler = exc_handler = mock.Mock()
async def foo(): async def foo():
await asyncio.sleep(0.1, loop=self.loop) await asyncio.sleep(0.1)
return 10 return 10
coro = foo() coro = foo()
...@@ -2479,7 +2468,7 @@ class SetMethodsTest: ...@@ -2479,7 +2468,7 @@ class SetMethodsTest:
self.loop.call_exception_handler = exc_handler = mock.Mock() self.loop.call_exception_handler = exc_handler = mock.Mock()
async def foo(): async def foo():
await asyncio.sleep(0.1, loop=self.loop) await asyncio.sleep(0.1)
return 10 return 10
coro = foo() coro = foo()
...@@ -3103,7 +3092,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase): ...@@ -3103,7 +3092,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
@asyncio.coroutine @asyncio.coroutine
def add(self, a, b, fail=False, cancel=False): def add(self, a, b, fail=False, cancel=False):
"""Wait 0.05 second and return a + b.""" """Wait 0.05 second and return a + b."""
yield from asyncio.sleep(0.05, loop=self.loop) yield from asyncio.sleep(0.05)
if fail: if fail:
raise RuntimeError("Fail!") raise RuntimeError("Fail!")
if cancel: if cancel:
...@@ -3213,7 +3202,7 @@ class SleepTests(test_utils.TestCase): ...@@ -3213,7 +3202,7 @@ class SleepTests(test_utils.TestCase):
def coro(): def coro():
self.loop.call_soon(inc_result, 1) self.loop.call_soon(inc_result, 1)
self.assertEqual(result, 0) self.assertEqual(result, 0)
num = yield from asyncio.sleep(0, loop=self.loop, result=10) num = yield from asyncio.sleep(0, result=10)
self.assertEqual(result, 1) # inc'ed by call_soon self.assertEqual(result, 1) # inc'ed by call_soon
inc_result(num) # num should be 11 inc_result(num) # num should be 11
...@@ -3221,7 +3210,7 @@ class SleepTests(test_utils.TestCase): ...@@ -3221,7 +3210,7 @@ class SleepTests(test_utils.TestCase):
self.assertEqual(result, 11) self.assertEqual(result, 11)
def test_loop_argument_is_deprecated(self): def test_loop_argument_is_deprecated(self):
# Remove test when loop argument is removed in Python 4.0 # Remove test when loop argument is removed in Python 3.10
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop)) self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
...@@ -3238,13 +3227,13 @@ class WaitTests(test_utils.TestCase): ...@@ -3238,13 +3227,13 @@ class WaitTests(test_utils.TestCase):
super().tearDown() super().tearDown()
def test_loop_argument_is_deprecated_in_wait(self): def test_loop_argument_is_deprecated_in_wait(self):
# Remove test when loop argument is removed in Python 4.0 # Remove test when loop argument is removed in Python 3.10
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait([coroutine_function()], loop=self.loop)) asyncio.wait([coroutine_function()], loop=self.loop))
def test_loop_argument_is_deprecated_in_wait_for(self): def test_loop_argument_is_deprecated_in_wait_for(self):
# Remove test when loop argument is removed in Python 4.0 # Remove test when loop argument is removed in Python 3.10
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete( self.loop.run_until_complete(
asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop)) asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))
...@@ -3268,7 +3257,7 @@ class CompatibilityTests(test_utils.TestCase): ...@@ -3268,7 +3257,7 @@ class CompatibilityTests(test_utils.TestCase):
@asyncio.coroutine @asyncio.coroutine
def coro(): def coro():
yield from asyncio.sleep(0, loop=self.loop) yield from asyncio.sleep(0)
return 'ok' return 'ok'
result = self.loop.run_until_complete(coro()) result = self.loop.run_until_complete(coro())
...@@ -3282,7 +3271,7 @@ class CompatibilityTests(test_utils.TestCase): ...@@ -3282,7 +3271,7 @@ class CompatibilityTests(test_utils.TestCase):
@asyncio.coroutine @asyncio.coroutine
def coro2(): def coro2():
yield from asyncio.sleep(0, loop=self.loop) yield from asyncio.sleep(0)
return 'ok2' return 'ok2'
async def inner(): async def inner():
......
...@@ -113,7 +113,7 @@ def run_until(loop, pred, timeout=30): ...@@ -113,7 +113,7 @@ def run_until(loop, pred, timeout=30):
timeout = deadline - time.time() timeout = deadline - time.time()
if timeout <= 0: if timeout <= 0:
raise futures.TimeoutError() raise futures.TimeoutError()
loop.run_until_complete(tasks.sleep(0.001, loop=loop)) loop.run_until_complete(tasks.sleep(0.001))
def run_once(loop): def run_once(loop):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment