Skip to content

Commit

Permalink
worker empty queue pause
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Sep 15, 2023
1 parent 1fc6f7f commit 701dcf5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_worker_pause.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from asyncio import get_event_loop, sleep
from typing import NamedTuple

from pytest import mark

from sharded_queue import Handler, Queue, Worker
from sharded_queue.drivers import RuntimeLock, RuntimeStorage
from sharded_queue.settings import settings


class SignContractRequest(NamedTuple):
document: int


signed: list[SignContractRequest] = []


class SignContract(Handler):
async def handle(self, *requests: SignContractRequest) -> None:
signed.extend(requests)


@mark.asyncio
async def test_worker_pause() -> None:
settings.worker_empty_pause = 0.1
queue: Queue = Queue(RuntimeStorage())
working_loop = Worker(RuntimeLock(), queue).loop(2)
worker_task = get_event_loop().create_task(working_loop)
get_event_loop().create_task(working_loop)
await queue.register(SignContract, SignContractRequest(1))
await sleep(0.2)
assert len(signed) == 1
await queue.register(SignContract, SignContractRequest(2))
await worker_task
assert len(signed) == 2

0 comments on commit 701dcf5

Please sign in to comment.