Skip to content

Commit 195bfea

Browse files
committed
fix according to CR
1 parent d54a5f0 commit 195bfea

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Lib/test/test_asyncio/test_locks.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ def test_cancel_release_race(self):
206206
# and 2 locks are taken at once.
207207
lock = asyncio.Lock(loop=self.loop)
208208
lock_count = 0
209+
call_count = 0
209210

210211
async def lockit():
211212
nonlocal lock_count
213+
nonlocal call_count
214+
call_count += 1
212215
await lock.acquire()
213216
lock_count += 1
214217

@@ -220,20 +223,31 @@ def trigger():
220223
t1.cancel()
221224
lock.release()
222225

223-
asyncio.Task(lockandtrigger(), loop=self.loop)
224-
t1 = asyncio.Task(lockit(), loop=self.loop)
225-
t2 = asyncio.Task(lockit(), loop=self.loop)
226-
t3 = asyncio.Task(lockit(), loop=self.loop)
226+
t0 = self.loop.create_task(lockandtrigger())
227+
t1 = self.loop.create_task(lockit())
228+
t2 = self.loop.create_task(lockit())
229+
t3 = self.loop.create_task(lockit())
227230

228231
# First loop acquires all
229232
test_utils.run_briefly(self.loop)
233+
self.assertTrue(t0.done())
234+
230235
# Second loop calls trigger
231236
test_utils.run_briefly(self.loop)
232237
# Third loop calls cancellation
233238
test_utils.run_briefly(self.loop)
234239

235240
# Make sure only one lock was taken
236241
self.assertEqual(lock_count, 1)
242+
# While 3 calls were made to lockit()
243+
self.assertEqual(call_count, 3)
244+
self.assertTrue(t1.cancelled() and t2.done())
245+
246+
# Cleanup the task that is stuck on acquire.
247+
t3.cancel()
248+
test_utils.run_briefly(self.loop)
249+
self.assertTrue(t3.cancelled())
250+
237251

238252

239253
def test_finished_waiter_cancelled(self):

0 commit comments

Comments
 (0)