Repository navigation
test(channel-affinity): stabilize usage-cache stats tests (flaky on Windows) - #6322
chillguyk5 wants to merge 1 commit into
Conversation
… keys Flaky root cause: tests keyed cache entries by time.Now().UnixNano(); on coarse-clock platforms (Windows) two tests in the same tick collide on the same entryKey in the global usage-cache-stats cache (TTL 600s), so counts accumulate cross-test (e.g. _ClaudeMode Total=1 + _MixedMode 2 observes -> Total=3 instead of 2). Replace with a package-level atomic.Int64 counter + t.Name() for per-test/per-invocation uniqueness (no clock dependency). Test-only; no production code changed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughChannel-affinity usage-cache tests replace timestamp-based key generation with an atomic sequence and shared helper, preserving existing assertions across Claude, mixed, and unsupported modes. ChangesAffinity cache test key generation
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
|
Closing — moving the work to a private custom repo instead of an upstream contribution. Feel free to reuse any of these changes if useful. Thanks for the project! |
📝 变更描述 / Description
稳定
service/channel_affinity_usage_cache_test.go中 2 个 flaky 测试(及同文件的_ClaudeMode,同模式):TestObserveChannelAffinityUsageCacheByRelayFormat_MixedModeTestObserveChannelAffinityUsageCacheByRelayFormat_UnsupportedModeKeepsEmptyRoot cause: 3 个测试用
time.Now().UnixNano()生成 cache key。在 wall-clock 粒度较粗的平台(典型为 Windows),两个在同一 tick 启动的测试得到相同纳秒 → 相同(ruleName, keyFingerprint)→ 全局 usage-cache-stats 缓存(TTL 600s)里相同 entryKey → 计数跨测试累加:_ClaudeMode(Total=1) +_MixedMode(2 次 observe) →_MixedMode读到Total=3而非 2 →require.EqualValues(2, stats.Total)失败。Fix: 用包级
atomic.Int64计数器(channelAffinityTestSeq)+t.Name()替换time.Now().UnixNano(),生成「按测试 + 按调用」唯一的 key,不依赖时钟。新增 helperaffinityTestKeys(t)。仅测试改动,不触碰生产代码。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
🔍 Note
service/channel_affinity_template_test.go仍用time.Now().UnixNano()(lines 207/242/282)作affinityValue/cacheKeySuffix。未被报告 flaky,本 PR 不动以避免范围蔓延;如后续 flake 可另开 follow-up 加固。Summary by CodeRabbit