test: 修复时段门控用例的时间相关 flaky(当地 23 点档必炸)

test_outside_session_no_fetch 此前用固定 23:00-23:59 模拟盘外时段,
但当测试跑在当地 23:00-23:59 时当前时刻恰好落在该时段内,断言必炸(本地
23 点后全量回归复现)。改为动态构造「当前时刻 +5~+6 分钟」的 1 分钟未来
时段,任何时刻运行都保证盘外。1263 全量通过。
This commit is contained in:
GitHub
2026-09-01 23:05:14 +08:00
parent 697fad71e1
commit bec231e8be
+7 -2
View File
@@ -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)