From bec231e8be1f6ffa1b3f9dc0ced9bd0429462826 Mon Sep 17 00:00:00 2001 From: GitHub Date: Tue, 1 Sep 2026 23:05:14 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E6=AE=B5?= =?UTF-8?q?=E9=97=A8=E6=8E=A7=E7=94=A8=E4=BE=8B=E7=9A=84=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=20flaky=EF=BC=88=E5=BD=93=E5=9C=B0=2023=20?= =?UTF-8?q?=E7=82=B9=E6=A1=A3=E5=BF=85=E7=82=B8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_outside_session_no_fetch 此前用固定 23:00-23:59 模拟盘外时段, 但当测试跑在当地 23:00-23:59 时当前时刻恰好落在该时段内,断言必炸(本地 23 点后全量回归复现)。改为动态构造「当前时刻 +5~+6 分钟」的 1 分钟未来 时段,任何时刻运行都保证盘外。1263 全量通过。 --- tests/unit/test_realtime_feed.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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)