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:
return asyncio.new_event_loop()
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):
self.__unhandled_exceptions.append(context)
......
......@@ -482,7 +482,7 @@ class BaseEventLoopTests(test_utils.TestCase):
pass
async def foo(delay):
await asyncio.sleep(delay, loop=self.loop)
await asyncio.sleep(delay)
def throw():
raise ShowStopper
......@@ -579,7 +579,7 @@ class BaseEventLoopTests(test_utils.TestCase):
@asyncio.coroutine
def zero_error_coro():
yield from asyncio.sleep(0.01, loop=self.loop)
yield from asyncio.sleep(0.01)
1/0
# Test Future.__del__
......
......@@ -64,7 +64,7 @@ class BaseTestBufferedProtocol(func_tests.FunctionalTestCaseMixin):
addr = srv.sockets[0].getsockname()
self.loop.run_until_complete(
asyncio.wait_for(client(addr), 5, loop=self.loop))
asyncio.wait_for(client(addr), 5))
srv.close()
self.loop.run_until_complete(srv.wait_closed())
......
......@@ -271,7 +271,7 @@ class EventLoopTestsMixin:
def test_run_until_complete(self):
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()
self.assertTrue(0.08 <= t1-t0 <= 0.8, t1-t0)
......@@ -279,7 +279,7 @@ class EventLoopTestsMixin:
async def cb():
self.loop.stop()
await asyncio.sleep(0.1, loop=self.loop)
await asyncio.sleep(0.1)
task = cb()
self.assertRaises(RuntimeError,
self.loop.run_until_complete, task)
......@@ -1757,11 +1757,11 @@ class EventLoopTestsMixin:
async def wait():
loop = self.loop
await asyncio.sleep(1e-2, loop=loop)
await asyncio.sleep(1e-4, loop=loop)
await asyncio.sleep(1e-6, loop=loop)
await asyncio.sleep(1e-8, loop=loop)
await asyncio.sleep(1e-10, loop=loop)
await asyncio.sleep(1e-2)
await asyncio.sleep(1e-4)
await asyncio.sleep(1e-6)
await asyncio.sleep(1e-8)
await asyncio.sleep(1e-10)
self.loop.run_until_complete(wait())
# The ideal number of call is 12, but on some platforms, the selector
......
......@@ -81,13 +81,13 @@ class LockTests(test_utils.TestCase):
@asyncio.coroutine
def test(lock):
yield from asyncio.sleep(0.01, loop=loop)
yield from asyncio.sleep(0.01)
self.assertFalse(lock.locked())
with self.assertWarns(DeprecationWarning):
with (yield from lock) as _lock:
self.assertIs(_lock, None)
self.assertTrue(lock.locked())
yield from asyncio.sleep(0.01, loop=loop)
yield from asyncio.sleep(0.01)
self.assertTrue(lock.locked())
self.assertFalse(lock.locked())
......@@ -819,8 +819,7 @@ class ConditionTests(test_utils.TestCase):
condition = asyncio.Condition(loop=loop)
async with condition:
with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for(condition.wait(), timeout=0.5,
loop=loop)
await asyncio.wait_for(condition.wait(), timeout=0.5)
loop.run_until_complete(task_timeout())
......
......@@ -52,12 +52,12 @@ class LockTests(BaseTest):
]
async def test(lock):
await asyncio.sleep(0.01, loop=self.loop)
await asyncio.sleep(0.01)
self.assertFalse(lock.locked())
async with lock as _lock:
self.assertIs(_lock, None)
self.assertTrue(lock.locked())
await asyncio.sleep(0.01, loop=self.loop)
await asyncio.sleep(0.01)
self.assertTrue(lock.locked())
self.assertFalse(lock.locked())
......@@ -74,13 +74,13 @@ class LockTests(BaseTest):
]
async def test(lock):
await asyncio.sleep(0.01, loop=self.loop)
await asyncio.sleep(0.01)
self.assertFalse(lock.locked())
with self.assertWarns(DeprecationWarning):
with await lock as _lock:
self.assertIs(_lock, None)
self.assertTrue(lock.locked())
await asyncio.sleep(0.01, loop=self.loop)
await asyncio.sleep(0.01)
self.assertTrue(lock.locked())
self.assertFalse(lock.locked())
......@@ -198,13 +198,13 @@ class CoroutineTests(BaseTest):
def test_double_await(self):
async def afunc():
await asyncio.sleep(0.1, loop=self.loop)
await asyncio.sleep(0.1)
async def runner():
coro = afunc()
t = asyncio.Task(coro, loop=self.loop)
try:
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
await coro
finally:
t.cancel()
......
......@@ -45,7 +45,7 @@ class QueueBasicTests(_QueueTestBase):
# Start a task that waits to get.
asyncio.Task(q.get(), loop=loop)
# Let it start waiting.
await asyncio.sleep(0.1, loop=loop)
await asyncio.sleep(0.1)
self.assertTrue('_getters[1]' in fn(q))
# resume q.get coroutine to finish generator
q.put_nowait(0)
......@@ -58,7 +58,7 @@ class QueueBasicTests(_QueueTestBase):
# Start a task that waits to put.
asyncio.Task(q.put(2), loop=loop)
# Let it start waiting.
await asyncio.sleep(0.1, loop=loop)
await asyncio.sleep(0.1)
self.assertTrue('_putters[1]' in fn(q))
# resume q.put coroutine to finish generator
q.get_nowait()
......@@ -135,14 +135,14 @@ class QueueBasicTests(_QueueTestBase):
async def test():
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.
self.assertEqual([0, 1], have_been_put)
self.assertEqual(0, q.get_nowait())
# 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(1, q.get_nowait())
self.assertEqual(2, q.get_nowait())
......@@ -234,11 +234,11 @@ class QueueGetTests(_QueueTestBase):
q = asyncio.Queue(loop=loop)
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():
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)
return await get_task
......@@ -297,7 +297,7 @@ class QueueGetTests(_QueueTestBase):
async def consumer(queue):
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:
pass
......@@ -364,7 +364,7 @@ class QueuePutTests(_QueueTestBase):
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(2)
......@@ -395,7 +395,7 @@ class QueuePutTests(_QueueTestBase):
reader2 = 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(2)
......@@ -424,7 +424,7 @@ class QueuePutTests(_QueueTestBase):
# putting a second item in the queue has to block (qsize=1)
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()
self.assertEqual(value1, 1)
......@@ -512,7 +512,7 @@ class QueuePutTests(_QueueTestBase):
await queue.put(item)
async def getter():
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
num = queue.qsize()
for _ in range(num):
item = queue.get_nowait()
......@@ -537,7 +537,7 @@ class QueuePutTests(_QueueTestBase):
# Task waiting for space to put an item in the queue.
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
# the task is canceled.
......@@ -560,7 +560,7 @@ class QueuePutTests(_QueueTestBase):
# Task waiting for space to put a item in the queue.
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.
queue.get_nowait()
......@@ -638,7 +638,7 @@ class _QueueJoinTestMixin:
running = False
for i in range(len(tasks)):
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):
q = self.q_class(loop=self.loop)
......
......@@ -195,7 +195,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_recv = mock.Mock()
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:],
(None, sock, 1024))
......@@ -215,7 +215,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
fut = 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))
callback = self.loop.add_reader.call_args[0][1]
params = self.loop.add_reader.call_args[0][2:]
......@@ -226,7 +226,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
sock.recv.side_effect = OSError(9)
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.assertEqual((10,), self.loop.remove_reader.call_args[0])
......@@ -278,7 +278,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
f = 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))
self.assertEqual(
(None, sock, b'data'),
......@@ -293,7 +293,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_sendall = mock.Mock()
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.assertIsNone(f.result())
......@@ -309,7 +309,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop.remove_writer = mock.Mock()
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]
params = self.loop.add_writer.call_args[0][2:]
......@@ -320,7 +320,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
sock.send.side_effect = OSError(9)
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.assertEqual((10,), self.loop.remove_writer.call_args[0])
......@@ -531,7 +531,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
self.loop._sock_accept = mock.Mock()
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.assertIs(self.loop._sock_accept.call_args[0][2], sock)
......
......@@ -252,7 +252,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True)
async def client(addr):
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)
on_data = self.loop.create_future()
on_eof = self.loop.create_future()
......@@ -271,7 +271,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
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):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
......@@ -332,7 +332,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True)
async def client(addr):
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)
on_data1 = self.loop.create_future()
on_data2 = self.loop.create_future()
......@@ -362,7 +362,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
self.loop.run_until_complete(
asyncio.wait_for(client(srv.addr),
loop=self.loop, timeout=self.TIMEOUT))
timeout=self.TIMEOUT))
def test_start_tls_slow_client_cancel(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
......@@ -403,7 +403,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.on_eof.set_result(True)
async def client(addr):
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)
on_data = self.loop.create_future()
on_eof = self.loop.create_future()
......@@ -418,12 +418,11 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
with self.assertRaises(asyncio.TimeoutError):
await asyncio.wait_for(
self.loop.start_tls(tr, proto, client_context),
0.5,
loop=self.loop)
0.5)
with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
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):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
......@@ -496,7 +495,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
timeout=self.TIMEOUT):
await asyncio.wait_for(
main(proto, on_con, on_eof, on_con_lost),
loop=self.loop, timeout=self.TIMEOUT)
timeout=self.TIMEOUT)
server.close()
await server.wait_closed()
......@@ -541,8 +540,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
ssl=client_sslctx,
server_hostname='',
ssl_handshake_timeout=10.0),
0.5,
loop=self.loop)
0.5)
with self.tcp_server(server,
max_clients=1,
......
......@@ -560,7 +560,7 @@ class StreamTests(test_utils.TestCase):
t1 = asyncio.Task(stream.readline(), 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)
......
......@@ -126,7 +126,7 @@ class SubprocessMixin:
return (exitcode, 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)
self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data')
......@@ -144,7 +144,7 @@ class SubprocessMixin:
return proc.returncode, stdout
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)
self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data')
......@@ -233,7 +233,7 @@ class SubprocessMixin:
proc, large_data = self.prepare_broken_pipe_test()
async def write_stdin(proc, data):
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)
proc.stdin.write(data)
await proc.stdin.drain()
......@@ -504,7 +504,7 @@ class SubprocessMixin:
while True:
data = await process.stdout.read(65536)
if data:
await asyncio.sleep(0.3, loop=self.loop)
await asyncio.sleep(0.3)
else:
break
......
This diff is collapsed.
......@@ -113,7 +113,7 @@ def run_until(loop, pred, timeout=30):
timeout = deadline - time.time()
if timeout <= 0:
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):
......
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