Skip to content

Deflake private access account-switch test - #44

Merged
AldanaBRZ merged 1 commit into
ankiquestfrom
fix-private-access-flake
Sep 28, 2026
Merged

AldanaBRZ merged 1 commit into
ankiquestfrom
fix-private-access-flake

Conversation

@float3

@float3 float3 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

account changes never send new server credentials to the captured server failed once on ubuntu (run 36316374916) with UnknownHostException: private.example.test.

Cause: the previous test's runFromSettings → present → AnkiquestWidget.requestUpdate(app) queues AnkiquestPollWorker. Ankiquest.app is left over from an earlier test, and the worker is a CoroutineWorker, so it runs on Dispatchers.Default and can outlive that test. Its dashboardUrl()/AnkiquestAvatars.account() read .all through the next test's switching mock, so the server switches before profile() reads it.

9fc9f2c made this deterministic by returning a snapshot to every read. That also let a second read inside endpoint() see the old server, which weakens the test.

  • Switch the server only for reads from the coroutine under test (a ThreadLocal context element that follows withContext(Dispatchers.IO)). Other readers see live prefs without switching.
  • The first read under test still gets the old values and later reads see the new server, so reading settings more than once fails again.
  • Assert that the switch happened.

AnkiquestPollWorker queued by an earlier test's present() runs on
Dispatchers.Default and can read settings through the next test's
switching mock first. Scope the switch to the coroutine under test and
assert it fired, instead of returning a fixed snapshot to every read.
@AldanaBRZ
AldanaBRZ merged commit 1c20315 into ankiquest Sep 28, 2026
26 of 27 checks passed
@float3
float3 deleted the fix-private-access-flake branch September 29, 2026 11:35
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.

2 participants