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
This diff is collapsed.
...@@ -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
......
This diff is collapsed.
...@@ -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