Avoid waiting before first queued message

This commit is contained in:
Kristóf Tóth 2019-10-07 13:10:37 +02:00
parent 15b4ab62e5
commit 0518716df8
2 changed files with 2 additions and 2 deletions

View File

@ -17,8 +17,8 @@ class MessageQueueHandler:
for message in iter(self._queue.get, None): for message in iter(self._queue.get, None):
wpm = message['wpm'] if 'wpm' in message else self.wpm wpm = message['wpm'] if 'wpm' in message else self.wpm
cps = 5 * wpm / 60 cps = 5 * wpm / 60
sleep(len(message['message']) / cps)
self.connector.send_message(message) self.connector.send_message(message)
sleep(len(message['message']) / cps)
def handle_event(self, message, _): def handle_event(self, message, _):
for unpacked in self._generate_messages_from_queue(message): for unpacked in self._generate_messages_from_queue(message):

View File

@ -60,7 +60,7 @@ def test_message_order(handler, queue):
def test_wpm(handler, queue): def test_wpm(handler, queue):
handler.wpm = 10000 handler.wpm = 10000
handler.connector.raise_event(queue) handler.connector.raise_event(queue)
assert not handler.connector.messages assert len(handler.connector.messages) == 1
handler.wpm = 100000000 handler.wpm = 100000000
handler.connector.raise_event(queue) handler.connector.raise_event(queue)
sleep(0.25) sleep(0.25)