test(consensus): expect redis namespace dual write
Some checks failed
CD Pipeline / tests (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
Code Review / ai-code-review (push) Has been cancelled

This commit is contained in:
Your Name
2026-05-05 13:41:41 +08:00
parent b00a7b050a
commit a57e3d3d75

View File

@@ -20,7 +20,7 @@ from __future__ import annotations
import re
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import ANY, AsyncMock, MagicMock, call, patch
import pytest
@@ -174,8 +174,13 @@ class TestConsensusEnginePersistsToPg:
await engine._save_consensus(result)
# Redis 寫(保留熱快取)
mock_redis.set.assert_called_once()
# Redis Phase A 雙寫(新 namespace + legacy 熱快取)
mock_redis.set.assert_has_calls(
[
call("__platform__:consensus:CS-TEST-001", ANY, ex=3600),
call("consensus:CS-TEST-001", ANY, ex=3600),
]
)
# PG 寫(永久記錄)
mock_db.execute.assert_called_once()
@@ -244,8 +249,13 @@ class TestConsensusEnginePersistsToPg:
# 不應拋例外
await engine._save_consensus(result)
# Redis 已完成(在 PG 嘗試之前)
mock_redis.set.assert_called_once()
# Redis Phase A 雙寫已完成(在 PG 嘗試之前)
mock_redis.set.assert_has_calls(
[
call("__platform__:consensus:CS-TEST-001", ANY, ex=3600),
call("consensus:CS-TEST-001", ANY, ex=3600),
]
)
# =============================================================================