MCPcopy Index your code
hub / github.com/python/cpython / test_wait_first_completed

Method test_wait_first_completed

Lib/test/test_asyncio/test_tasks.py:1192–1219  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1190 sleep_coro.close()
1191
1192 def test_wait_first_completed(self):
1193
1194 def gen():
1195 when = yield
1196 self.assertAlmostEqual(10.0, when)
1197 when = yield 0
1198 self.assertAlmostEqual(0.1, when)
1199 yield 0.1
1200
1201 loop = self.new_test_loop(gen)
1202
1203 a = self.new_task(loop, asyncio.sleep(10.0))
1204 b = self.new_task(loop, asyncio.sleep(0.1))
1205 task = self.new_task(
1206 loop,
1207 asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
1208
1209 done, pending = loop.run_until_complete(task)
1210 self.assertEqual({b}, done)
1211 self.assertEqual({a}, pending)
1212 self.assertFalse(a.done())
1213 self.assertTrue(b.done())
1214 self.assertIsNone(b.result())
1215 self.assertAlmostEqual(0.1, loop.time())
1216
1217 # move forward to close generator
1218 loop.advance_time(10)
1219 loop.run_until_complete(asyncio.wait([a, b]))
1220
1221 def test_wait_really_done(self):
1222 # there is possibility that some tasks in the pending list

Callers

nothing calls this directly

Calls 14

new_taskMethod · 0.95
new_test_loopMethod · 0.80
assertFalseMethod · 0.80
assertTrueMethod · 0.80
assertIsNoneMethod · 0.80
advance_timeMethod · 0.80
sleepMethod · 0.45
waitMethod · 0.45
run_until_completeMethod · 0.45
assertEqualMethod · 0.45
doneMethod · 0.45
resultMethod · 0.45

Tested by

no test coverage detected