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

Aperta Adatta ai principianti
#798 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mithunkc017-ship-it ci sta già lavorando.

Dal 12/11/2026.

  • #799 di @mithunkc017-ship-it — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
testing

Direzione di ricerca

Leggi backend/services/matchmaking_test.go e confronta il suo schema di pulizia con quello di backend/services/matchmaking_pool_test.go. Esegui il comando go test dell’issue per riprodurre i conteggi del pool condiviso, quindi assicurati che ogni test rimuova tutti gli utenti che aggiunge. Il lavoro è completato quando le esecuzioni ripetute passano senza che gli utenti rimasti influenzino le asserzioni sulla dimensione del pool.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
107
Fork
263
Merge medio
7h 54m
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AOSSIE-Org/DebateAI

Tutte le issue di AOSSIE-Org/DebateAI

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.