diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-05-22 12:01:45 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-05-22 12:01:45 +0300 |
| commit | 7ef81bfa0076969dad277b9b1bf7ff2246355ff4 (patch) | |
| tree | c56dda192b4690bda2b700344645c6661bd286c6 /test.py | |
| parent | 3017c675f3ab78c7bc29bd548d955e195165c829 (diff) | |
Use monotonic clock for task ordering
Diffstat (limited to 'test.py')
| -rw-r--r-- | test.py | 22 |
1 files changed, 4 insertions, 18 deletions
@@ -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) |
