aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-05-15 13:01:52 +0300
committerJan Tuomi <jan@jantuomi.fi>2025-05-15 13:01:52 +0300
commit3de71d936f28a305e18bdc98bf136b1d2c643eea (patch)
tree4bc773e0470c8ffa6b7e072ea86ef83052b8777f /test.py
parentaf38085446b6e4b40ff3bdc09d2dbfdae9dba564 (diff)
Only pop() tasks added with past timestamp
Diffstat (limited to 'test.py')
-rw-r--r--test.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test.py b/test.py
index 2ae9c48..144d9ce 100644
--- a/test.py
+++ b/test.py
@@ -170,6 +170,40 @@ class TestFemtoQueue(unittest.TestCase):
# Queue should now be empty
self.assertIsNone(q.pop())
+ def test_only_past_tasks_are_popped(self):
+ dir = mkdtemp()
+ q = FemtoQueue(data_dir=dir, node_id="node1")
+
+ set_time_mock(1000)
+ q.push("foobar".encode("utf-8"))
+
+ set_time_mock(0)
+ task = q.pop()
+ self.assertIsNone(task)
+
+ set_time_mock(2000)
+ task = q.pop()
+ self.assertIsNotNone(task)
+
+ reset_time_mock()
+
+ def test_schedule_for_future(self):
+ dir = mkdtemp()
+ q = FemtoQueue(data_dir=dir, node_id="node1")
+
+ future_ts = time.time() + 60
+ future_ts_us = int(1_000_000 * future_ts)
+ q.push("foobar".encode("utf-8"), time_us=future_ts_us)
+
+ task = q.pop()
+ self.assertIsNone(task)
+
+ set_time_mock(future_ts + 60)
+ task = q.pop()
+ self.assertIsNotNone(task)
+
+ reset_time_mock()
+
if __name__ == "__main__":
unittest.main()