[BUG]: Singleton state leak in matchmaking tests causes non-deterministic failures

未关闭 适合新手
#798 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mithunkc017-ship-it 已经在做这个了。

开始于 2026年11月12日。

  • #799 来自 @mithunkc017-ship-it —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
testing

调研方向

阅读 backend/services/matchmaking_test.go,并将其清理模式与 backend/services/matchmaking_pool_test.go 进行比较。运行 issue 的 go test 命令以复现共享池计数,然后确保每个测试都删除它添加的所有用户。重复运行均通过,且没有遗留用户影响池大小断言,即为完成。

由索引模型根据 Issue 内容生成。

描述

bug
Bug Description

TestMatchmakingService and TestEloTolerance in services/matchmaking_test.go both operate on the same package-level MatchmakingService singleton (initialised once via sync.Once). Neither test registers a t.Cleanup to remove the users it adds to the pool.

Specifically, TestMatchmakingService adds user1 and user2, then removes only user1. user2 stays in the shared pool indefinitely. When TestEloTolerance runs afterwards, it adds its own user1/user2/user3 and asserts exact pool counts — but the leftover user2 from the previous test makes those counts wrong, causing the test to fail non-deterministically depending on run order and timing.

This is in contrast to matchmaking_pool_test.go, which already correctly uses t.Cleanup to remove every entry it adds.

Steps to Reproduce
  • Run the matchmaking service tests multiple times or in verbose mode :
go test ./services/... -v -count=3 -run "TestMatchmakingService|TestEloTolerance"
  • Observe intermittent failures on pool size assertions such as:
    Expected 0 users in pool (no one started matchmaking), got 1
    or
    Expected 1 user remaining in pool (Charlie), got 2
Logs and Screenshots
--- FAIL: TestEloTolerance (0.11s)
    matchmaking_test.go:79: Expected 0 users in pool (no one started matchmaking), got 1
--- FAIL: TestEloTolerance (0.11s)
    matchmaking_test.go:110: Expected 1 user remaining in pool (Charlie), got 2

The failure is non-deterministic — it surfaces more reliably with -count=2 or higher, or when tests run in parallel.

Environment Details
  • Language: Go
  • Affected file: backend/services/matchmaking_test.go
  • Related file (correct pattern): backend/services/matchmaking_pool_test.go
  • Root cause: GetMatchmakingService() uses sync.Once — all tests share the same singleton pool with no isolation between test runs
  • Go version: Any (not version-specific)
  • OS: Any
Impact

Medium - Feature works but has issues

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
主要语言
TypeScript
星标
107
派生
263
平均合并
7 小时 54 分钟
30 天内合并 PR
12

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AOSSIE-Org/DebateAI 的其他 Issue

查看 AOSSIE-Org/DebateAI 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。