Skip to content

improve test_log_destroyed_pending_task in asyncio #129821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,6 @@ def test_wait_invalid_args(self):
asyncio.wait([]))

def test_log_destroyed_pending_task(self):
Task = self.__class__.Task

async def kill_me(loop):
future = self.new_future(loop)
Expand All @@ -2269,7 +2268,7 @@ async def kill_me(loop):

# schedule the task
coro = kill_me(self.loop)
task = asyncio.ensure_future(coro, loop=self.loop)
task = self.new_task(self.loop, coro)

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

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

self.assertEqual(self.all_tasks(loop=self.loop), set())

mock_handler.assert_called_with(self.loop, {
'message': 'Task was destroyed but it is pending!',
'task': mock.ANY,
'source_traceback': source_traceback,
})
mock_handler.reset_mock()
# task got resurrected by the exception handler
support.gc_collect()

self.assertEqual(self.all_tasks(loop=self.loop), set())


@mock.patch('asyncio.base_events.logger')
def test_tb_logger_not_called_after_cancel(self, m_log):
Expand Down
Loading