Skip to content

Commit 673755b

Browse files
authored
bpo-47076: Make asyncio.Queue stable on slow test boxes (GH-32040)
1 parent 49daf6d commit 673755b

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

Lib/test/test_asyncio/test_queues.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def _test_repr_or_str(self, fn, expect_id):
2828
# Start a task that waits to get.
2929
getter = tg.create_task(q.get())
3030
# Let it start waiting.
31-
await asyncio.sleep(0.1)
31+
await asyncio.sleep(0)
3232
self.assertTrue('_getters[1]' in fn(q))
3333
# resume q.get coroutine to finish generator
3434
q.put_nowait(0)
@@ -42,7 +42,7 @@ async def _test_repr_or_str(self, fn, expect_id):
4242
# Start a task that waits to put.
4343
putter = tg.create_task(q.put(2))
4444
# Let it start waiting.
45-
await asyncio.sleep(0.1)
45+
await asyncio.sleep(0)
4646
self.assertTrue('_putters[1]' in fn(q))
4747
# resume q.put coroutine to finish generator
4848
q.get_nowait()
@@ -100,14 +100,15 @@ async def putter():
100100
return True
101101

102102
t = asyncio.create_task(putter())
103-
await asyncio.sleep(0.01)
103+
for i in range(2):
104+
await asyncio.sleep(0)
104105

105106
# The putter is blocked after putting two items.
106107
self.assertEqual([0, 1], have_been_put)
107108
self.assertEqual(0, await q.get())
108109

109110
# Let the putter resume and put last item.
110-
await asyncio.sleep(0.01)
111+
await asyncio.sleep(0)
111112
self.assertEqual([0, 1, 2], have_been_put)
112113
self.assertEqual(1, await q.get())
113114
self.assertEqual(2, await q.get())
@@ -150,10 +151,10 @@ async def queue_get():
150151
finished = True
151152
return res
152153

153-
loop.call_later(0.01, q.put_nowait, 1)
154154
queue_get_task = asyncio.create_task(queue_get())
155155
await started.wait()
156156
self.assertFalse(finished)
157+
loop.call_later(0.01, q.put_nowait, 1)
157158
res = await queue_get_task
158159
self.assertTrue(finished)
159160
self.assertEqual(1, res)
@@ -167,17 +168,6 @@ def test_nonblocking_get_exception(self):
167168
q = asyncio.Queue()
168169
self.assertRaises(asyncio.QueueEmpty, q.get_nowait)
169170

170-
async def test_get_cancelled(self):
171-
q = asyncio.Queue()
172-
173-
async def queue_get():
174-
return await asyncio.wait_for(q.get(), 0.051)
175-
176-
get_task = asyncio.create_task(queue_get())
177-
await asyncio.sleep(0.01) # let the task start
178-
q.put_nowait(1)
179-
self.assertEqual(1, await get_task)
180-
181171
async def test_get_cancelled_race(self):
182172
q = asyncio.Queue()
183173

@@ -263,7 +253,7 @@ async def test_get_cancel_drop_one_pending_reader(self):
263253

264254
reader = asyncio.create_task(q.get())
265255

266-
await asyncio.sleep(0.01)
256+
await asyncio.sleep(0)
267257

268258
q.put_nowait(1)
269259
q.put_nowait(2)
@@ -288,7 +278,7 @@ async def test_get_cancel_drop_many_pending_readers(self):
288278
reader2 = tg.create_task(q.get())
289279
reader3 = tg.create_task(q.get())
290280

291-
await asyncio.sleep(0.01)
281+
await asyncio.sleep(0)
292282

293283
q.put_nowait(1)
294284
q.put_nowait(2)
@@ -309,7 +299,7 @@ async def test_put_cancel_drop(self):
309299

310300
# putting a second item in the queue has to block (qsize=1)
311301
writer = asyncio.create_task(q.put(2))
312-
await asyncio.sleep(0.01)
302+
await asyncio.sleep(0)
313303

314304
value1 = q.get_nowait()
315305
self.assertEqual(value1, 1)
@@ -410,7 +400,7 @@ async def test_cancelled_puts_not_being_held_in_self_putters(self):
410400

411401
# Task waiting for space to put an item in the queue.
412402
put_task = asyncio.create_task(queue.put(1))
413-
await asyncio.sleep(0.01)
403+
await asyncio.sleep(0)
414404

415405
# Check that the putter is correctly removed from queue._putters when
416406
# the task is canceled.
@@ -427,7 +417,7 @@ async def test_cancelled_put_silence_value_error_exception(self):
427417

428418
# Task waiting for space to put a item in the queue.
429419
put_task = asyncio.create_task(queue.put(1))
430-
await asyncio.sleep(0.01)
420+
await asyncio.sleep(0)
431421

432422
# get_nowait() remove the future of put_task from queue._putters.
433423
queue.get_nowait()

0 commit comments

Comments
 (0)