Skip to content

Commit 49bd47d

Browse files
improve test_log_destroyed_pending_task in asyncio (#129821)
1 parent 662e88d commit 49bd47d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: Lib/test/test_asyncio/test_tasks.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,6 @@ def test_wait_invalid_args(self):
22542254
asyncio.wait([]))
22552255

22562256
def test_log_destroyed_pending_task(self):
2257-
Task = self.__class__.Task
22582257

22592258
async def kill_me(loop):
22602259
future = self.new_future(loop)
@@ -2269,7 +2268,7 @@ async def kill_me(loop):
22692268

22702269
# schedule the task
22712270
coro = kill_me(self.loop)
2272-
task = asyncio.ensure_future(coro, loop=self.loop)
2271+
task = self.new_task(self.loop, coro)
22732272

22742273
self.assertEqual(self.all_tasks(loop=self.loop), {task})
22752274

@@ -2286,14 +2285,17 @@ async def kill_me(loop):
22862285
# no more reference to kill_me() task: the task is destroyed by the GC
22872286
support.gc_collect()
22882287

2289-
self.assertEqual(self.all_tasks(loop=self.loop), set())
2290-
22912288
mock_handler.assert_called_with(self.loop, {
22922289
'message': 'Task was destroyed but it is pending!',
22932290
'task': mock.ANY,
22942291
'source_traceback': source_traceback,
22952292
})
22962293
mock_handler.reset_mock()
2294+
# task got resurrected by the exception handler
2295+
support.gc_collect()
2296+
2297+
self.assertEqual(self.all_tasks(loop=self.loop), set())
2298+
22972299

22982300
@mock.patch('asyncio.base_events.logger')
22992301
def test_tb_logger_not_called_after_cancel(self, m_log):

0 commit comments

Comments
 (0)