Skip to content

test: make matchmaking tests deterministic - #822

Open
RounakKumarAgarwal wants to merge 2 commits into
AOSSIE-Org:mainfrom
RounakKumarAgarwal:fix/issue-760-flaky-matchmaking-test
Open

RounakKumarAgarwal wants to merge 2 commits into
AOSSIE-Org:mainfrom
RounakKumarAgarwal:fix/issue-760-flaky-matchmaking-test

Conversation

@RounakKumarAgarwal

@RounakKumarAgarwal RounakKumarAgarwal commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #760

Problem

TestMatchmakingService was flaky because Alice (1200) and Bob (1250) are inside each other's ±200 range. The background matcher could pair and remove both users before the test checked the pool.

There was also a second problem: the tests share one matchmaking service and never cleaned up, so Charlie from TestEloTolerance stayed in the pool and broke the next run.

Changes

Tests only, no change to the matchmaking logic.

  • Use Elo 1200 and 2000 so the two users can never be matched.
  • Each test uses its own user IDs and removes them with t.Cleanup.
  • Assert only on the test's own users instead of the global pool size.
  • TestEloTolerance: wait for Alice and Bob to be matched (up to 2s) instead of a fixed 100ms sleep, and check Charlie with a direct matching pass instead of sleeping. Charlie also moves from 800 to 700: at 800 his range (600–1000) touched Alice's (1000–1400), so they could match.

Testing

Windows 11, Git Bash.

Before (on main): passes on the 1st run, fails on every run after that:

$ go test ./services/ -run 'TestMatchmaking|TestEloTolerance' -count=20
--- FAIL: TestMatchmakingService (0.00s)
    matchmaking_test.go:26: Expected 0 users in pool (no one started matchmaking), got 1
FAIL    arguehub/services       6.729s

After (with this PR):
Screenshot 2026-11-29 142250

$ go test ./services/ -run 'TestMatchmaking|TestEloTolerance' -count=20
ok      arguehub/services       5.021s

$ go test ./services/ -count=3
ok      arguehub/services       0.960s

Summary by CodeRabbit

  • Tests
    • Improved matchmaking test isolation by using unique users and cleaning up test data.
    • Updated matching checks to verify individual pool membership and wait for expected pool changes.

TestMatchmakingService used Elo 1200 and 1250, which are inside each
other's +-200 range, so the background matcher could pair and remove
both users before the test checked the pool.

- use 1200 and 2000 so the two users can never be matched
- give each test its own user IDs and remove them with t.Cleanup, so
  leftovers from one test (e.g. Charlie) can't affect the next run
- assert only on the test's own users instead of the global pool size
- TestEloTolerance: wait for the match instead of a fixed 100ms sleep,
  and move Charlie to 700 (range 500-900); at 800 his range touched
  Alice's at 1000 and the two could match

Fixes AOSSIE-Org#760

Signed-off-by: Rounak Agarwal <agarwalrounak2005@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The matchmaking tests now use unique user IDs, clean up their users, and check each user’s pool membership. The Elo tolerance test waits for Alice and Bob to leave the pool, then checks that Charlie remains.

Changes: Matchmaking test reliability

Layer / File(s) Summary
Isolate test users and verify pool membership
backend/services/matchmaking_test.go
Both tests use unique user IDs and cleanup. TestMatchmakingService checks each user’s membership and uses Elo values with non-overlapping match ranges. TestEloTolerance waits up to two seconds for Alice and Bob to leave the pool, then calls findMatch directly and checks that Charlie remains.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Low

Possibly related issues

Possibly related PRs

  • AOSSIE-Org/DebateAI#786 — Both PRs change Elo values in the matchmaking test to prevent users from matching during pool assertions.

Suggested reviewers: rixitgithub

Merge Risk: Minimal · up to 04bde

This is a test-only change that makes the matchmaking tests deterministic. It does not touch production code, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title 'test: make matchmaking tests deterministic' matches the main change. The PR changes only backend/services/matchmaking_test.go to remove the race between the background matcher and pool asse…
Linked Issues check Passed Issue #760 is the only directly linked issue. Its coding requirement is a deterministic fix for TestMatchmakingService in backend/services/matchmaking_test.go, with no change to matchmaking logic. At …
Out of Scope Changes check Passed The PR changes only backend/services/matchmaking_test.go, according to the PR description and the raw summary. Every change in that file supports issue #760: Elo value changes, unique per-test IDs, t.…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title 'test: make matchmaking tests deterministic' matches the main change. The PR changes only backend/services/matchmaking_test.go to remove the race between the background matcher and pool assertions, using non-overlapping Elo values, unique user IDs, cleanup, and membership-based assertions. The title is concise, specific, and follows the conventional commit style. No unrelated or misleading content is present.

Full details: Linked Issues check

Explanation

Issue #760 is the only directly linked issue. Its coding requirement is a deterministic fix for TestMatchmakingService in backend/services/matchmaking_test.go, with no change to matchmaking logic. At the reviewed head, TestMatchmakingService uses Alice at 1200 (range 1000-1400) and Bob at 2000 (range 1800-2200). The ranges do not overlap, so findMatch in matchmaking.go cannot pair them. The test uses unique IDs, registers t.Cleanup, and checks pool membership per user instead of global pool size. This matches the issue's proposed fix. TestEloTolerance waits up to 2s for Alice (1200) and Bob (1250) to match. Charlie is at 700 (range 500-900), which does not overlap either. Charlie's check calls ms.findMatch synchronously, so the result does not depend on a sleep. The helpers poolContains and waitUntil are defined in matchmaking_pool_test.go at the reviewed head, in the same package. I did not run the tests. The pass rests on source reading and the PR's reported runs.

Full details: Out of Scope Changes check

Explanation

The PR changes only backend/services/matchmaking_test.go, according to the PR description and the raw summary. Every change in that file supports issue #760: Elo value changes, unique per-test IDs, t.Cleanup removal, per-user assertions, the wait loop in TestEloTolerance, and the synchronous findMatch call. matchmaking.go matches the described behaviour and shows no changes tied to this PR. The whole-PR diff tool was unavailable (changed blobs missing from the checkout), so the file list rests on the summary. The line counts in the raw summary (+73/-77) differ from the earlier review (+62/-78). I could not confirm the cause of that difference. No unrelated change was found in the evidence I could read.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 833d3638-c74e-4423-ab41-ec12f86b5ac3
Commits

Reviewing files that changed from the base of the PR and between eebcf13 and 04bde34.

Files selected for processing: 1

  • backend/services/matchmaking_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Call findMatch synchronously so the 'no compatible opponent' check
doesn't depend on a fixed 200ms sleep, and check AddToPool errors in
TestEloTolerance like the other tests do.

Signed-off-by: Rounak Agarwal <agarwalrounak2005@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Flaky test – TestMatchmakingService fails intermittently (users matched before pool assertion)

1 participant