Skip to content

test: stop two phone unit tests racing their mock servers - #516

Closed
RXWatcher wants to merge 2 commits into
Silo-Server:mainfrom
RXWatcher:fix/libraries-recheck-test-race
Closed

RXWatcher wants to merge 2 commits into
Silo-Server:mainfrom
RXWatcher:fix/libraries-recheck-test-race

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

Two phone unit tests fail intermittently and block unrelated pull requests:

Approach

The test fixture's mock engine resumed LibrariesViewModel on an IO thread after every response. A library load could therefore finish while the test called refreshLibraryList() again on the test thread. The call saw the old load still active and queued a re-check, but the finishing loop had already decided not to repeat. No request followed, and awaitRequest waited until the test timed out. The app runs this code on its single main thread, so the race exists only in the test.

Library recheck tests: the fixture now takes an optional engine dispatcher. The four recheck tests run the mock engine on StandardTestDispatcher(testScheduler), which keeps the view model and the test on one scheduler. Other tests are unchanged.

Pick Another test: the view model publishes the new pick and its reset countdown in two updates, and the skip response resumes it off the test thread. The test waited only for the new pick, then read the countdown, which could still hold the old value. It now waits for both.

This changes only test code.

Validation

  • LibrariesViewModelTest 10 times in a row with --rerun-tasks: all passed. Before the change, unmodified main failed the class 2 of 15 runs, always in a recheck test.
  • PlayerViewModelLoadOwnershipIntegrationTest 6 times in a row with --rerun-tasks: all passed.

Evidence

Evidence: none, no user-visible change

Risks

None identified. Test-only change.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, GitHub CLI, Gradle
  • Model(s): claude-opus-5-5[1m]
  • Involvement: AI-generated, directed by the contributor; human review pending
  • Adversarial review: n/a for a test-only fix. The diagnosis was checked by comparing failure rates before and after on unmodified main; no independent agent reviewed it.

🤖 Generated with Claude Code

Note

Stop mock-server races in phone unit tests by tying MockEngine to the test scheduler

  • Adds an optional dispatcher to DeferredLibrariesFixture in LibrariesViewModelTest.kt. Four library-list recheck tests pass a StandardTestDispatcher backed by the current test scheduler, so mock HTTP handling and view-model resumptions run on the same virtual clock instead of racing real threads.
  • The fixture registers its request handling via MockEngineConfig.addHandler and only overrides the dispatcher when one is supplied; callers that omit it keep the default MockEngine behavior.
  • In PlayerViewModelLoadOwnershipIntegrationTest.kt, the shuffle-selection await-state predicate now also waits for the reset up-next countdown value, not just the expected episode content ID.

Macroscope summarized 1669a61.

…uler

The libraryListRecheck* tests flaked with UncompletedCoroutinesError on CI
and locally. Each mock response resumed LibrariesViewModel on an IO
thread, so a library load could finish concurrently with the test's next
refreshLibraryList(): the call saw the old job still active, queued a
re-check the finishing loop never ran, and the test waited a minute for a
request that never came. The app runs this on one main thread, so only
the test was racy. Run these tests' mock engine on the test scheduler.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@silo-kody

silo-kody Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6bb3b158-2145-494f-a564-e24d8a92c9f0
📥 Commits

Reviewing files that changed from the base of the PR and between bfa6188 and 100ae7a.

📒 Files selected for processing (1)
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/libraries/LibrariesViewModelTest.kt

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


📝 Walkthrough

Walkthrough

The library ViewModel test fixture now accepts an optional dispatcher for mock-engine work. Four library-list recheck tests provide a StandardTestDispatcher tied to the test scheduler.

Changes

Library ViewModel test dispatcher

Layer / File(s) Summary
Mock-engine dispatcher and recheck tests
androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/libraries/LibrariesViewModelTest.kt
The fixture accepts an optional dispatcher and applies it to MockEngineConfig. Four recheck tests pass a dispatcher tied to the test scheduler. Request selection and response handling remain unchanged.

Priority: ⬇️ Low

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

Change: Other

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 100ae

This change only affects unit tests, so users see no behavior change. It makes the library recheck tests less likely to fail intermittently, and there is no merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the test-only reliability fix for two phone unit tests affected by race conditions.
Description check ✅ Passed The description directly explains the intermittent test failures, the scheduler-based fixes, validation results, and the absence of user-visible changes.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/libraries-recheck-test-race
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · 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

Comment @coderabbitai help to get the list of available commands.

@Quick104 Quick104 added priority: P2 Limited scope, workaround exists, or polish impact: polish Annoyance, cosmetic, or nice-to-have labels Oct 8, 2026 — with Cursor
pickAnotherReplacesThePickWithAFullCountdownAndStopEndsTheShuffle flaked:
the new pick and its reset countdown are published in two updates, and
the skip response resumes the view model off the test thread, so the test
could see the new episode while the countdown still held the old value.
Wait for both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@silo-kody

silo-kody Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@RXWatcher RXWatcher changed the title test(libraries): stop the library recheck tests racing their mock engine test: stop two phone unit tests racing their mock servers Oct 8, 2026
@RXWatcher

Copy link
Copy Markdown
Contributor Author

Closing: main already fixes both flaky tests, in #510 (library recheck fixtures on the test scheduler) and #513 (shuffle countdown on one scheduler).

@RXWatcher RXWatcher closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants