mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fix: correct lock and workers
This commit is contained in:
parent
515e5769ef
commit
96ad8d8ed9
2 changed files with 49 additions and 30 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -17,10 +18,11 @@ except ImportError:
|
|||
from unittest.mock import patch
|
||||
|
||||
pytestmarm = pytest.mark.asyncio
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestChatActionSender:
|
||||
initial_sleep = 1.0
|
||||
initial_sleep = 0.5
|
||||
|
||||
async def test_wait_with_event(self, bot: Bot, loop: asyncio.BaseEventLoop):
|
||||
sender = ChatActionSender.typing(bot=bot, chat_id=42)
|
||||
|
|
@ -35,11 +37,6 @@ class TestChatActionSender:
|
|||
await sender._wait(self.initial_sleep)
|
||||
assert time.monotonic() - start >= self.initial_sleep
|
||||
|
||||
async def test_initial_sleep(self, bot: Bot):
|
||||
start = time.monotonic()
|
||||
async with ChatActionSender.typing(bot=bot, chat_id=42, initial_sleep=self.initial_sleep):
|
||||
assert time.monotonic() - start >= self.initial_sleep
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"action",
|
||||
[
|
||||
|
|
@ -71,12 +68,26 @@ class TestChatActionSender:
|
|||
new_callable=CoroutineMock,
|
||||
) as mocked_send_chat_action:
|
||||
async with ChatActionSender.typing(
|
||||
bot=bot, chat_id=42, interval=0.01, initial_sleep=0
|
||||
bot=bot, chat_id=42, interval=0.01, initial_sleep=0.0
|
||||
):
|
||||
await asyncio.sleep(0.1)
|
||||
assert mocked_send_chat_action.await_count > 1
|
||||
mocked_send_chat_action.assert_awaited_with(action="typing", chat_id=42)
|
||||
|
||||
async def test_worker_with_initial_sleep(self, bot: Bot):
|
||||
start = time.monotonic()
|
||||
with patch(
|
||||
"aiogram.client.bot.Bot.send_chat_action",
|
||||
new_callable=CoroutineMock,
|
||||
) as mocked_send_chat_action:
|
||||
async with ChatActionSender.typing(
|
||||
bot=bot, chat_id=42, interval=0.01, initial_sleep=self.initial_sleep
|
||||
):
|
||||
assert time.monotonic() - start >= self.initial_sleep
|
||||
await asyncio.sleep(0.1)
|
||||
assert mocked_send_chat_action.await_count > 1
|
||||
mocked_send_chat_action.assert_awaited_with(action="typing", chat_id=42)
|
||||
|
||||
async def test_contextmanager(self, bot: MockedBot):
|
||||
sender: ChatActionSender = ChatActionSender.typing(bot=bot, chat_id=42)
|
||||
assert not sender.running
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue