diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2024-10-01 01:37:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-01 01:37:27 (GMT) |
commit | 133e929a791d209b578b4822a7a07f4570b3803b (patch) | |
tree | de0a1d104737285e3a5709dd7e95dc603413ca11 /Lib/test/test_asyncio | |
parent | 7bdfabe2d1ec353ecdc75a5aec41cce83e572391 (diff) | |
download | cpython-133e929a791d209b578b4822a7a07f4570b3803b.zip cpython-133e929a791d209b578b4822a7a07f4570b3803b.tar.gz cpython-133e929a791d209b578b4822a7a07f4570b3803b.tar.bz2 |
gh-124309: Revert eager task factory fix to prevent breaking downstream (#124810)
* Revert "GH-124639: add back loop param to staggered_race (#124700)"
This reverts commit e0a41a5dd12cb6e9277b05abebac5c70be684dd7.
* Revert "gh-124309: Modernize the `staggered_race` implementation to support eager task factories (#124390)"
This reverts commit de929f353c413459834a2a37b2d9b0240673d874.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_eager_task_factory.py | 47 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_staggered.py | 56 |
2 files changed, 4 insertions, 99 deletions
diff --git a/Lib/test/test_asyncio/test_eager_task_factory.py b/Lib/test/test_asyncio/test_eager_task_factory.py index 1579ad1..0777f39 100644 --- a/Lib/test/test_asyncio/test_eager_task_factory.py +++ b/Lib/test/test_asyncio/test_eager_task_factory.py @@ -213,53 +213,6 @@ class EagerTaskFactoryLoopTests: self.run_coro(run()) - def test_staggered_race_with_eager_tasks(self): - # See https://github.com/python/cpython/issues/124309 - - async def fail(): - await asyncio.sleep(0) - raise ValueError("no good") - - async def run(): - winner, index, excs = await asyncio.staggered.staggered_race( - [ - lambda: asyncio.sleep(2, result="sleep2"), - lambda: asyncio.sleep(1, result="sleep1"), - lambda: fail() - ], - delay=0.25 - ) - self.assertEqual(winner, 'sleep1') - self.assertEqual(index, 1) - self.assertIsNone(excs[index]) - self.assertIsInstance(excs[0], asyncio.CancelledError) - self.assertIsInstance(excs[2], ValueError) - - self.run_coro(run()) - - def test_staggered_race_with_eager_tasks_no_delay(self): - # See https://github.com/python/cpython/issues/124309 - async def fail(): - raise ValueError("no good") - - async def run(): - winner, index, excs = await asyncio.staggered.staggered_race( - [ - lambda: fail(), - lambda: asyncio.sleep(1, result="sleep1"), - lambda: asyncio.sleep(0, result="sleep0"), - ], - delay=None - ) - self.assertEqual(winner, 'sleep1') - self.assertEqual(index, 1) - self.assertIsNone(excs[index]) - self.assertIsInstance(excs[0], ValueError) - self.assertEqual(len(excs), 2) - - self.run_coro(run()) - - class PyEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase): Task = tasks._PyTask diff --git a/Lib/test/test_asyncio/test_staggered.py b/Lib/test/test_asyncio/test_staggered.py index 8cd9839..e6e32f7 100644 --- a/Lib/test/test_asyncio/test_staggered.py +++ b/Lib/test/test_asyncio/test_staggered.py @@ -82,64 +82,16 @@ class StaggeredTests(unittest.IsolatedAsyncioTestCase): async def coro(index): raise ValueError(index) - for delay in [None, 0, 0.1, 1]: - with self.subTest(delay=delay): - winner, index, excs = await staggered_race( - [ - lambda: coro(0), - lambda: coro(1), - ], - delay=delay, - ) - - self.assertIs(winner, None) - self.assertIs(index, None) - self.assertEqual(len(excs), 2) - self.assertIsInstance(excs[0], ValueError) - self.assertIsInstance(excs[1], ValueError) - - async def test_long_delay_early_failure(self): - async def coro(index): - await asyncio.sleep(0) # Dummy coroutine for the 1 case - if index == 0: - await asyncio.sleep(0.1) # Dummy coroutine - raise ValueError(index) - - return f'Res: {index}' - winner, index, excs = await staggered_race( [ lambda: coro(0), lambda: coro(1), ], - delay=10, + delay=None, ) - self.assertEqual(winner, 'Res: 1') - self.assertEqual(index, 1) + self.assertIs(winner, None) + self.assertIs(index, None) self.assertEqual(len(excs), 2) self.assertIsInstance(excs[0], ValueError) - self.assertIsNone(excs[1]) - - def test_loop_argument(self): - loop = asyncio.new_event_loop() - async def coro(): - self.assertEqual(loop, asyncio.get_running_loop()) - return 'coro' - - async def main(): - winner, index, excs = await staggered_race( - [coro], - delay=0.1, - loop=loop - ) - - self.assertEqual(winner, 'coro') - self.assertEqual(index, 0) - - loop.run_until_complete(main()) - loop.close() - - -if __name__ == "__main__": - unittest.main() + self.assertIsInstance(excs[1], ValueError) |