feat: add tests, CI and P0 reliability features

This commit is contained in:
strsv committed 2026-11-06 07:43:30 +03:00
1 parent 0754065dae
commit 626650e44a
22 files changed
+1576 -49

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
"""Tests for the background job manager."""
import os
import sys
import time
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "tools"))
sys.path.insert(0, os.path.join(ROOT, "web"))
import server
class JobManagerTests(unittest.TestCase):
def wait_for(self, predicate, timeout=5):
deadline = time.time() + timeout
while time.time() < deadline:
if predicate():
return True
time.sleep(0.05)
return False
def test_start_cancel_and_finish(self):
jobs = server.JobManager()
self.assertTrue(jobs.start("test", ["-c", "import time; time.sleep(30)"]))
try:
self.assertTrue(self.wait_for(lambda: jobs.status()["running"]))
self.assertFalse(jobs.start("test", ["-c", "pass"]), "only one job at a time")
self.assertTrue(jobs.cancel())
self.assertTrue(self.wait_for(lambda: not jobs.status()["running"]))
state = jobs.status()
self.assertTrue(state["cancelled"])
self.assertIsNotNone(state["finished_at"])
self.assertFalse(jobs.cancel(), "nothing left to cancel")
finally:
jobs.cancel()
def test_cancel_without_job(self):
jobs = server.JobManager()
self.assertFalse(jobs.cancel())
if __name__ == "__main__":
unittest.main()