From c691752adf6ddb02a9ae43a4e64c24bdc7d60e0e Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Thu, 24 Nov 2022 15:11:33 -0500 Subject: [PATCH] Add unit test for cancel_callback --- tests/test_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 00000000..fab371b9 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,17 @@ +from channels.utils import await_many_dispatch +import asyncio +import async_timeout +from unittest import mock +import pytest + +async def sleep_task(*args): + await asyncio.sleep(10) + +@pytest.mark.asyncio +async def test_cancel_callback_called(): + cancel_callback = mock.AsyncMock() + with pytest.raises(asyncio.TimeoutError): + async with async_timeout.timeout(0): + await await_many_dispatch([sleep_task], sleep_task, cancel_callback) + print(cancel_callback.__dict__) + assert cancel_callback.called