mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-06-28 02:32:02 +08:00
fix(logic): isolate atomic batch counters and token sync fields
This commit is contained in:
21
tests/test_batch_task_manager.py
Normal file
21
tests/test_batch_task_manager.py
Normal 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
|
||||
Reference in New Issue
Block a user