diff options
| author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2022-03-22 14:02:51 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-22 14:02:51 (GMT) |
| commit | 32e77154ddfc514a3144d5912bffdd957246fd6c (patch) | |
| tree | 862472617c97dc822ea1dbc33cd3e0396090ebb1 /Lib/test/test_asyncio/test_locks.py | |
| parent | 673755bfbac46b3cd2c84d7e0d68c2c488e039c3 (diff) | |
| download | cpython-32e77154ddfc514a3144d5912bffdd957246fd6c.zip cpython-32e77154ddfc514a3144d5912bffdd957246fd6c.tar.gz cpython-32e77154ddfc514a3144d5912bffdd957246fd6c.tar.bz2 | |
bpo-45997: Fix asyncio.Semaphore re-acquiring order (GH-31910)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_asyncio/test_locks.py')
| -rw-r--r-- | Lib/test/test_asyncio/test_locks.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py index d8b164a..920b3b5 100644 --- a/Lib/test/test_asyncio/test_locks.py +++ b/Lib/test/test_asyncio/test_locks.py @@ -917,6 +917,31 @@ class SemaphoreTests(unittest.IsolatedAsyncioTestCase): sem.release() self.assertFalse(sem.locked()) + async def test_acquire_fifo_order(self): + sem = asyncio.Semaphore(1) + result = [] + + async def coro(tag): + await sem.acquire() + result.append(f'{tag}_1') + await asyncio.sleep(0.01) + sem.release() + + await sem.acquire() + result.append(f'{tag}_2') + await asyncio.sleep(0.01) + sem.release() + + async with asyncio.TaskGroup() as tg: + tg.create_task(coro('c1')) + tg.create_task(coro('c2')) + tg.create_task(coro('c3')) + + self.assertEqual( + ['c1_1', 'c2_1', 'c3_1', 'c1_2', 'c2_2', 'c3_2'], + result + ) + if __name__ == '__main__': unittest.main() |
