Skip to content

Commit 68c63fa

Browse files
committed
Add unit test for cancel_callback
1 parent d7c96e2 commit 68c63fa

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from channels.utils import await_many_dispatch
2+
import asyncio
3+
import async_timeout
4+
from unittest import mock
5+
import pytest
6+
7+
8+
async def sleep_task(*args):
9+
await asyncio.sleep(10)
10+
11+
12+
@pytest.mark.asyncio
13+
async def test_cancel_callback_called():
14+
cancel_callback = mock.AsyncMock()
15+
with pytest.raises(asyncio.TimeoutError):
16+
async with async_timeout.timeout(0):
17+
await await_many_dispatch([sleep_task], sleep_task, cancel_callback)
18+
assert cancel_callback.called

0 commit comments

Comments
 (0)