Fix concurrent checklist sync and consistent actions

This commit is contained in:
Codex 2026-10-04 20:19:03 +01:00
parent a33f7a297d
commit 8d5a94d7fa
10 changed files with 124 additions and 20 deletions

View file

@ -1,5 +1,6 @@
import tempfile
import unittest
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import app
@ -30,6 +31,21 @@ class StoreTests(unittest.TestCase):
self.assertFalse(snapshot["checks"]["crop-parsnip"])
self.assertEqual(snapshot["revision"], 2)
def test_two_clients_keep_distinct_concurrent_changes(self):
second_client = app.Store(self.store.path)
def write(index):
store = self.store if index % 2 else second_client
store.set_check(f"concurrent-item-{index}", True, f"player-{index % 2}")
with ThreadPoolExecutor(max_workers=2) as pool:
list(pool.map(write, range(20)))
snapshot = self.store.snapshot()
self.assertEqual(snapshot["revision"], 20)
self.assertEqual(len(snapshot["checks"]), 20)
self.assertTrue(all(snapshot["checks"].values()))
if __name__ == "__main__":
unittest.main()