From: Ben Darnell Date: Sun, 21 Jan 2018 20:27:34 +0000 (-0500) Subject: gen_test: Add test for asyncio.gather X-Git-Tag: v5.0.0~13^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ec7dca027f6333ce07d7eae4124586536ec7f8a;p=thirdparty%2Ftornado.git gen_test: Add test for asyncio.gather This is additional verification that the asyncio integration is working as intended. Fixes #1684 --- diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index ff7d9770a..6850af81c 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -1069,6 +1069,20 @@ class GenCoroutineTest(AsyncTestCase): actual = repr(coro) self.assertIn(expected, actual) + @unittest.skipIf(asyncio is None, "asyncio module not present") + @gen_test + def test_asyncio_gather(self): + # This demonstrates that tornado coroutines can be understood + # by asyncio (This failed prior to Tornado 5.0). + @gen.coroutine + def f(): + yield gen.moment + raise gen.Return(1) + + ret = yield asyncio.gather(f(), f()) + self.assertEqual(ret, [1, 1]) + self.finished = True + class GenSequenceHandler(RequestHandler): @asynchronous