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

Open Beginner friendly
#798 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 20 days

@mithunkc017-ship-it is already working on this.

Since Nov 12, 2026.

  • #799 by @mithunkc017-ship-it — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
testing

Research direction

Read backend/services/matchmaking_test.go and compare its cleanup pattern with backend/services/matchmaking_pool_test.go. Run the issue’s go test command to reproduce the shared pool counts, then ensure each test removes every user it adds. Done means repeated runs pass without leftover users affecting pool size assertions.

Written by the indexing model from the issue text.

Description

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
Dominant language
TypeScript
Stars
108
Forks
266
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/DebateAI

All issues in AOSSIE-Org/DebateAI

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.