aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/test.py b/test.py
index 144d9ce..13db3c1 100644
--- a/test.py
+++ b/test.py
@@ -7,6 +7,7 @@ from femtoqueue import FemtoQueue, FemtoTask
from tempfile import mkdtemp
original_time_fn = time.time
+original_monotonic_fn = time.monotonic
def set_time_mock(ts: float):
@@ -14,10 +15,12 @@ def set_time_mock(ts: float):
return ts
time.time = mock_time_fn
+ time.monotonic = mock_time_fn
def reset_time_mock():
time.time = original_time_fn
+ time.monotonic = original_monotonic_fn
class TestFemtoQueue(unittest.TestCase):
@@ -170,30 +173,13 @@ 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)
+ q.schedule("foobar".encode("utf-8"), time_us=future_ts_us)
task = q.pop()
self.assertIsNone(task)