summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncgen.py
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2020-02-13 00:15:38 -0800
committerGitHub <noreply@github.com>2020-02-13 00:15:38 -0800
commit925dc7fb1d0db85dc137afa4cd14211bf0d67414 (patch)
treec03ac2612f81cd6135dc9f084a491fb8663b260f /Lib/test/test_asyncgen.py
parent7514f4f6254f4a2d13ea8e5632a8e5f22b637e0b (diff)
downloadcpython-git-925dc7fb1d0db85dc137afa4cd14211bf0d67414.tar.gz
bpo-39606: allow closing async generators that are already closed (GH-18475)
The fix for [bpo-39386](https://bugs.python.org/issue39386) attempted to make it so you couldn't reuse a agen.aclose() coroutine object. It accidentally also prevented you from calling aclose() at all on an async generator that was already closed or exhausted. This commit fixes it so we're only blocking the actually illegal cases, while allowing the legal cases. The new tests failed before this patch. Also confirmed that this fixes the test failures we were seeing in Trio with Python dev builds: https://github.com/python-trio/trio/pull/1396 https://bugs.python.org/issue39606
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r--Lib/test/test_asyncgen.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 24b20bec2b..fb6321d226 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -1128,7 +1128,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
self.assertEqual([], messages)
- def test_async_gen_await_anext_twice(self):
+ def test_async_gen_await_same_anext_coro_twice(self):
async def async_iterate():
yield 1
yield 2
@@ -1147,7 +1147,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
self.loop.run_until_complete(run())
- def test_async_gen_await_aclose_twice(self):
+ def test_async_gen_await_same_aclose_coro_twice(self):
async def async_iterate():
yield 1
yield 2
@@ -1164,6 +1164,32 @@ class AsyncGenAsyncioTest(unittest.TestCase):
self.loop.run_until_complete(run())
+ def test_async_gen_aclose_twice_with_different_coros(self):
+ # Regression test for https://bugs.python.org/issue39606
+ async def async_iterate():
+ yield 1
+ yield 2
+
+ async def run():
+ it = async_iterate()
+ await it.aclose()
+ await it.aclose()
+
+ self.loop.run_until_complete(run())
+
+ def test_async_gen_aclose_after_exhaustion(self):
+ # Regression test for https://bugs.python.org/issue39606
+ async def async_iterate():
+ yield 1
+ yield 2
+
+ async def run():
+ it = async_iterate()
+ async for _ in it:
+ pass
+ await it.aclose()
+
+ self.loop.run_until_complete(run())
if __name__ == "__main__":
unittest.main()