MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_wait

Method test_wait

test/asynchronous/test_locks.py:31–92  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

29 # - https://github.com/python/cpython/issues/112202
30 class TestConditionStdlib(unittest.IsolatedAsyncioTestCase):
31 async def test_wait(self):
32 cond = _async_create_condition(_async_create_lock())
33 result = []
34
35 async def c1(result):
36 await cond.acquire()
37 if await cond.wait():
38 result.append(1)
39 return True
40
41 async def c2(result):
42 await cond.acquire()
43 if await cond.wait():
44 result.append(2)
45 return True
46
47 async def c3(result):
48 await cond.acquire()
49 if await cond.wait():
50 result.append(3)
51 return True
52
53 t1 = asyncio.create_task(c1(result))
54 t2 = asyncio.create_task(c2(result))
55 t3 = asyncio.create_task(c3(result))
56
57 await asyncio.sleep(0)
58 self.assertEqual([], result)
59 self.assertFalse(cond.locked())
60
61 self.assertTrue(await cond.acquire())
62 cond.notify()
63 await asyncio.sleep(0)
64 self.assertEqual([], result)
65 self.assertTrue(cond.locked())
66
67 cond.release()
68 await asyncio.sleep(0)
69 self.assertEqual([1], result)
70 self.assertTrue(cond.locked())
71
72 cond.notify(2)
73 await asyncio.sleep(0)
74 self.assertEqual([1], result)
75 self.assertTrue(cond.locked())
76
77 cond.release()
78 await asyncio.sleep(0)
79 self.assertEqual([1, 2], result)
80 self.assertTrue(cond.locked())
81
82 cond.release()
83 await asyncio.sleep(0)
84 self.assertEqual([1, 2, 3], result)
85 self.assertTrue(cond.locked())
86
87 self.assertTrue(t1.done())
88 self.assertTrue(t1.result())

Callers

nothing calls this directly

Calls 6

_async_create_conditionFunction · 0.90
_async_create_lockFunction · 0.90
lockedMethod · 0.80
acquireMethod · 0.80
notifyMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected