Skip to content

test(persistence): cover account switch with live readers on the outgoing db - #1499

Merged
bmc08gt merged 1 commit into
code/cashfrom
test/persistence-account-switch-readers
Sep 18, 2026
Merged

bmc08gt merged 1 commit into
code/cashfrom
test/persistence-account-switch-readers

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

FlipcashDatabase.init closes the outgoing instance when the entropy changes, so an account switch can pull the database out from under code that is still reading it. FlipcashDatabaseInitTest covered instance identity across that switch but never held a reader on the outgoing instance, so the behaviour readers actually see was untested.

Room 2.8.5 is what surfaced the gap: it made suspending queries and invalidation-tracker operations throw IllegalStateException once the database is closed.

Two cases:

  • A suspending query against the outgoing DAO must fail rather than read through a closed pool. This asserts the failure and not its type — close() cancels Room's internal scope before the new IllegalStateException can fire, so the query surfaces a CancellationException instead, and pinning the type would break on either side of that race.
  • A live Flow collector on the outgoing DAO must not be handed an exception. A screen still observing the previous account should stop receiving updates, not crash.

Both pass on 2.8.4 and 2.8.5, so this locks in current behaviour rather than fixing a defect. Removing the account switch from the first test makes it fail, so the assertions are not vacuous.

…oing db

FlipcashDatabase.init closes the outgoing instance when the entropy changes, but
neither existing test held a reader on that instance across the switch. Room
2.8.5 made suspending queries throw IllegalStateException once the database is
closed, which is what makes that gap worth covering.

Two cases: a suspending query against the outgoing DAO must fail rather than read
through a closed pool, and a live Flow collector on the outgoing DAO must not be
handed an exception. The first asserts the failure and not its type, because
close() cancels Room's internal scope before the new IllegalStateException can
fire, so the query surfaces a CancellationException instead.
@bmc08gt bmc08gt self-assigned this Sep 18, 2026
@github-actions github-actions Bot added the type: test Test additions or improvements label Sep 18, 2026
@bmc08gt
bmc08gt merged commit 83ad1c5 into code/cash Sep 18, 2026
3 checks passed
@bmc08gt
bmc08gt deleted the test/persistence-account-switch-readers branch September 23, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: test Test additions or improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant