perf(signal_v2): raise stock_client TTL for NAS load relief (SP-A1)

portfolio  60s → 180s (3분 폴링 → 3회당 1회 fetch)
news-sent 300s → 600s (sentiment는 자주 안 바뀜)
screener   60s → 300s (Top-20 분 단위 변화 미미)

V2 재시작 시점부터 NAS stock에 대한 인바운드 호출이
분당 12 → 분당 3~4 로 감소 예상. 캐시 hit ratio 0~50% → 66~80%.
회귀 테스트 3건 추가로 미래 의도치 않은 TTL 변경 차단.

Also update test_stock_client.py fake_time assertions from 61.0 → 181.0
to match the new 180s portfolio TTL (tests were TTL-dependent).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 21:37:49 +09:00
parent 71ef959310
commit bb03cc4525
3 changed files with 28 additions and 9 deletions

View File

@@ -34,7 +34,7 @@ async def test_get_portfolio_normal_returns_dict_with_pnl_pct(mock_stock_api):
async def test_get_portfolio_uses_cache_within_ttl(mock_stock_api):
"""60s TTL 내 두번째 호출 = mock 콜 1회."""
"""180s TTL 내 두번째 호출 = mock 콜 1회."""
route = mock_stock_api.get("/api/webai/portfolio").mock(
return_value=httpx.Response(
200, json={"holdings": [], "cash": [], "summary": {}}
@@ -56,7 +56,7 @@ async def test_get_portfolio_refetches_after_ttl_expiry(mock_stock_api, monkeypa
200, json={"holdings": [], "cash": [], "summary": {}}
)
)
# Fake clock: starts at 0, jumps to 61 between calls
# Fake clock: starts at 0, jumps past portfolio TTL (180s) between calls
fake_time = [0.0]
monkeypatch.setattr(
"signal_v2.stock_client.time.monotonic", lambda: fake_time[0]
@@ -65,7 +65,7 @@ async def test_get_portfolio_refetches_after_ttl_expiry(mock_stock_api, monkeypa
client = StockClient(BASE_URL, API_KEY)
try:
await client.get_portfolio()
fake_time[0] = 61.0 # 60s TTL 만료
fake_time[0] = 181.0 # 180s TTL 만료
await client.get_portfolio()
assert route.call_count == 2
finally:
@@ -152,8 +152,8 @@ async def test_get_portfolio_falls_back_to_stale_on_all_failures(
first = await client.get_portfolio()
assert first["holdings"][0]["ticker"] == "005930"
# Advance fake clock past TTL (60s) so cache is stale
fake_time[0] = 61.0
# Advance fake clock past TTL (180s) so cache is stale
fake_time[0] = 181.0
# Now mock to return 500s persistently
route1.mock(return_value=httpx.Response(500, text="server error"))