feat: complete client runtime foundation
This commit is contained in:
+29
-1
@@ -1,9 +1,10 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
import os
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from archive_clients.state import ClientStore, CommandConflict
|
||||
from archive_clients.state import ClientStore, CommandConflict, JobConflict
|
||||
|
||||
|
||||
class ClientStoreTests(unittest.TestCase):
|
||||
@@ -12,6 +13,7 @@ class ClientStoreTests(unittest.TestCase):
|
||||
database = Path(directory) / "state.db"
|
||||
store = ClientStore(database)
|
||||
store.initialize()
|
||||
self.assertEqual(os.stat(database).st_mode & 0o777, 0o600)
|
||||
command_id = str(uuid4())
|
||||
first = store.accept_command(command_id, '{"b":2,"a":1}', '{"ok":true}')
|
||||
duplicate = ClientStore(database).accept_command(
|
||||
@@ -23,6 +25,32 @@ class ClientStoreTests(unittest.TestCase):
|
||||
with self.assertRaises(CommandConflict):
|
||||
store.accept_command(command_id, '{"a":2}', '{"ok":true}')
|
||||
|
||||
def test_job_definition_is_immutable_while_cursor_advances(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
store = ClientStore(Path(directory) / "state.db")
|
||||
store.initialize()
|
||||
store.save_job(
|
||||
"job-1", '{"jobId":"job-1"}', "JOB_STATE_WAITING",
|
||||
1, 2, False,
|
||||
)
|
||||
store.save_job(
|
||||
"job-1", '{"jobId":"job-1"}', "JOB_STATE_RUNNING",
|
||||
2, 3, False,
|
||||
)
|
||||
self.assertEqual(
|
||||
store.job_snapshot_rows(["job-1"])[0]["revision"], 2
|
||||
)
|
||||
with self.assertRaisesRegex(JobConflict, "backwards"):
|
||||
store.save_job(
|
||||
"job-1", '{"jobId":"job-1"}', "JOB_STATE_WAITING",
|
||||
1, 2, False,
|
||||
)
|
||||
with self.assertRaises(JobConflict):
|
||||
store.save_job(
|
||||
"job-1", '{"jobId":"other"}', "JOB_STATE_RUNNING",
|
||||
2, 3, False,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user