fix(logic): isolate atomic batch counters and token sync fields

This commit is contained in:
Mison
2026-03-23 11:23:31 +08:00
parent 16154bb5ae
commit cf571d37c1
7 changed files with 294 additions and 104 deletions

View File

@@ -0,0 +1,21 @@
from concurrent.futures import ThreadPoolExecutor
from src.web.task_manager import task_manager
def test_record_batch_task_result_is_atomic_under_threads():
batch_id = "batch-atomic-test"
task_manager.init_batch(batch_id, 100)
statuses = ["completed"] * 60 + ["failed"] * 40
with ThreadPoolExecutor(max_workers=16) as executor:
list(executor.map(lambda status: task_manager.record_batch_task_result(batch_id, status), statuses))
snapshot = task_manager.get_batch_status(batch_id)
assert snapshot is not None
assert snapshot["completed"] == 100
assert snapshot["success"] == 60
assert snapshot["failed"] == 40
assert snapshot["skipped"] == 0