diff --git a/tests/unit/test_realtime_feed.py b/tests/unit/test_realtime_feed.py index 10b4b91..9b76d5a 100644 --- a/tests/unit/test_realtime_feed.py +++ b/tests/unit/test_realtime_feed.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio import time +from datetime import datetime from unittest.mock import MagicMock import pandas as pd @@ -277,11 +278,15 @@ class TestSessionGating: bus = EventBus() client = AsyncMockClient([_sample_quotes_df()]) - # 用一个不可能命中的时段(如 23:00-23:59)模拟盘外 + # 动态构造一个「永远在未来」的 1 分钟时段,保证当前时刻必在盘外。 + # 此前用固定 23:00-23:59 模拟盘外——测试跑在当地 23 点档时必炸 + # (时间相关 flaky)。 + _now = datetime.now() + now_min = _now.hour * 60 + _now.minute feed = RealtimeDataFeed( bus=bus, symbols=[(0, "000001")], - sessions=((23 * 60, 23 * 60 + 59),), + sessions=(((now_min + 5) % (24 * 60), (now_min + 6) % (24 * 60)),), interval=0.1, ) await feed.run_async(client, max_iterations=1)