test(alerting): close the coroutine the create_task mock intercepts

update_values builds periodic_flush() before handing it to the patched
asyncio.create_task, which neither schedules nor closes it, so garbage
collection emits an unawaited-coroutine warning. That is noise normally and
an error under -W error.

Applies to the pre-existing start test as well: it patches create_task the
same way, so fixing only the new one would leave the warning in place.
This commit is contained in:
jeishod 2026-08-27 15:28:56 +01:00
parent 3c2c089a9e
commit f16a63ebf9

View file

@ -15,6 +15,16 @@ from litellm.proxy._types import CallInfo, Litellm_EntityType
from litellm.types.integrations.slack_alerting import SlackAlertingCacheKeys
def _close_and_stub(coro):
"""asyncio.create_task stand-in: close the coroutine nothing will await.
Leaving it open emits an unawaited-coroutine warning, which is an error
under -W error.
"""
coro.close()
return MagicMock()
class TestSlackAlerting(unittest.TestCase):
def setUp(self):
self.slack_alerting = SlackAlerting()
@ -156,8 +166,7 @@ class TestSlackAlerting(unittest.TestCase):
# Calling update_values with alerting args should try to start the periodic task
@patch("asyncio.create_task")
def test_update_values_starts_periodic_task(self, mock_create_task):
# Make it do nothing (or return a dummy future)
mock_create_task.return_value = AsyncMock() # prevents awaiting errors
mock_create_task.side_effect = _close_and_stub
assert self.slack_alerting.periodic_started == False
@ -169,7 +178,7 @@ class TestSlackAlerting(unittest.TestCase):
# never exits, so they accumulate for the lifetime of the process).
@patch("asyncio.create_task")
def test_update_values_starts_periodic_task_only_once(self, mock_create_task):
mock_create_task.return_value = AsyncMock()
mock_create_task.side_effect = _close_and_stub
for _ in range(5):
self.slack_alerting.update_values(alerting=["slack"])