test(consensus): expect redis namespace dual write
This commit is contained in:
@@ -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),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user