Skip to content

Commit

Permalink
Add unit test for cancel_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterseth committed Nov 24, 2022
1 parent d7c96e2 commit c691752
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c691752

Please sign in to comment.