AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] Flaky test:test_kb_rate_limiter.py::test_concurrent_waiters_keep_the_configured_interval[0] 在 macos-latest 上偶发失败

Open silvaling opened this issue 2 months ago • 0 comments

问题描述

Unit Tests 工作流的 macos-latest lane 因 tests/test_kb_rate_limiter.py:34 的一条计时断言失败,同一 commit 在 ubuntu-latest 上通过,套件其余部分全绿(1 failed, 3631 passed, 5 skipped)。

tests/test_kb_rate_limiter.py::test_concurrent_waiters_keep_the_configured_interval[0]
E  AssertionError: [0.12367229100004806, 0.08920287499995538, 0.10840137500002811, 0.10127545899996448, 0.1012895410000283]
E  assert 0.08920287499995538 >= 0.09

RateLimiter(600) 的调用间隔为 60 / 600 = 0.1 s,测试给了 10% 容差(min(gaps) >= 0.09);实测最小间隔 0.08920 s,比容差低了 0.8 ms。

如何复现?

https://github.com/AstrBotDevs/AstrBot/actions/runs/36587137473/job/109470342854?pr=8169

错误日志

___________________________ test_concurrent_waiters_keep_the_configured_interval[0] ___________________________

event_loop_stall = 0

    @pytest.mark.asyncio
    @pytest.mark.parametrize("event_loop_stall", [0, 0.4])
    async def test_concurrent_waiters_keep_the_configured_interval(event_loop_stall):
        limiter = RateLimiter(600)  # 0.1 s between calls
        ...
        times.sort()
        gaps = [b - a for a, b in zip(times, times[1:])]
        assert len(gaps) == 5
        # Every pair of consecutive calls must be at least the interval apart
        # (small tolerance for timer granularity).
>       assert min(gaps) >= 0.09, gaps
E       AssertionError: [0.12367229100004806, 0.08920287499995538, 0.10840137500002811, 0.10127545899996448, 0.1012895410000283]
E       assert 0.08920287499995538 >= 0.09
E        +  where 0.08920287499995538 = min([0.12367229100004806, 0.08920287499995538, 0.10840137500002811, 0.10127545899996448, 0.1012895410000283])

tests/test_kb_rate_limiter.py:34: AssertionError
============================= 1 failed, 3631 passed, 5 skipped, 36 warnings in 257.55s (0:04:17) =============================

检查清单

  • [x] 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • [x] 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • [x] 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • [x] 我已阅读并同意本项目的贡献者行为准则。

silvaling avatar Sep 29 '26 15:09 silvaling