From 5e569f16cbb9f61a0c52501250a8902bc5b82132 Mon Sep 17 00:00:00 2001 From: dmitry krokhin Date: Wed, 22 Nov 2023 15:46:47 +0300 Subject: [PATCH] deferred reqeust timestamp calculation fix --- sharded_queue/__init__.py | 2 +- tests/test_recurrent.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sharded_queue/__init__.py b/sharded_queue/__init__.py index 804d85c..1dbe040 100644 --- a/sharded_queue/__init__.py +++ b/sharded_queue/__init__.py @@ -285,7 +285,7 @@ def calculate_timestamp(cls, delta: float | int | timedelta) -> float: timestamp: float = now.timestamp() if not isinstance(delta, timedelta): - timestamp = delta = delta + timestamp = timestamp + delta return timestamp diff --git a/tests/test_recurrent.py b/tests/test_recurrent.py index 3155dc9..b9832c6 100644 --- a/tests/test_recurrent.py +++ b/tests/test_recurrent.py @@ -45,10 +45,15 @@ async def stats() -> tuple[int, int, int]: ) assert await stats() == (0, 1, 0), 'recurrent pipe contains request' + deffered_registration = datetime.now().timestamp() await Worker(lock, queue).loop(1) assert await stats() == (1, 1, 0), 'added defered request' assert await lock.exists(recurrent_pipe) + [deferred] = await queue.storage.range(deferred_pipe, 1) + request = queue.serializer.deserialize(DeferredRequest, deferred) + assert request.timestamp >= deffered_registration + await lock.release(recurrent_pipe) await Worker(lock, queue).loop(1, handler=RecurrentHandler) assert await stats() == (1, 1, 0), 'no deffered duplicates'