Prhub

#45345 [CI][BugFix] Fix broken `test_mamba_prefix_cache.py` due to stale mock

原始 PR 作者 njhill 合并时间 2026-06-12 11:26 文件变更 1 提交数 1 评论 0 代码增减 +2 / -0

执行摘要

修复测试 mock 与新版 KVCacheManager 签名不匹配

PR #44594 变更了 KVCacheManager.allocate_slots() 的方法签名,新增 has_scheduled_reqs 参数,但相应的测试 mock 未同步更新,导致 test_mamba_prefix_cache.py 因签名不匹配而失败。由于该测试未被触发运行,问题未被及时发现。

此类伴随重构的测试更新非常重要,建议 CI 中增加对涉及变更模块的相关测试的自动触发机制,避免遗漏。

讨论亮点

无 review 讨论,已获得批准。

实现拆解

  1. tests/v1/e2e/general/test_mamba_prefix_cache.pyfake_allocate_slots_fn mock 函数形参列表中新增 has_scheduled_reqs: bool = True 参数。
  2. 在调用 original_allocate_slots_fn 时将 has_scheduled_reqs 参数透传。
    此改动仅涉及测试代码,不修改任何生产逻辑。
文件 模块 状态 重要度
tests/v1/e2e/general/test_mamba_prefix_cache.py Mamba 前缀缓存 modified 3.7

关键源码片段

tests/v1/e2e/general/test_mamba_prefix_cache.py test-coverage

测试 mock 函数签名与生产代码不同步,导致测试失败;本 PR 修复该问题。

# 修复后的 mock 函数:补全了 `has_scheduled_reqs` 参数
# 与 KVCacheManager.allocate_slots 的最新签名保持一致
def get_fake_allocate_slots_fn(original_allocate_slots_fn: Callable):
    def fake_allocate_slots_fn(
        self: KVCacheManager,
        request: Request,
        num_new_tokens: int,
        num_new_computed_tokens: int = 0,
        new_computed_blocks: KVCacheBlocks | None = None,
        num_lookahead_tokens: int = 0,
        num_external_computed_tokens: int = 0,
        delay_cache_blocks: bool = False,
        num_encoder_tokens: int = 0,
        full_sequence_must_fit: bool = False,
        reserved_blocks: int = 0,
        has_scheduled_reqs: bool = True, # 新增参数,默认 True
    ):
        ret = original_allocate_slots_fn(
            self,
            request,
            num_new_tokens,
            num_new_computed_tokens,
            new_computed_blocks,
            num_lookahead_tokens,
            num_external_computed_tokens,
            delay_cache_blocks,
            num_encoder_tokens,
            full_sequence_must_fit,
            reserved_blocks,
            has_scheduled_reqs, # 透传参数
        )
        # 其余验证逻辑不变
        # ...
        return ret
​
    return fake_allocate_slots_fn

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

无风险。仅修改测试 mock,与生产代码完全解耦,且变更极小。

影响范围仅限于修复 test_mamba_prefix_cache.py 测试,使其能通过且正确验证 KVCacheManager.allocate_slots 的行为。

测试遗漏

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论