Repository navigation
test(persistence): cover account switch with live readers on the outgoing db - #1499
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FlipcashDatabase.initcloses the outgoing instance when the entropy changes, so an account switch can pull the database out from under code that is still reading it.FlipcashDatabaseInitTestcovered 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
IllegalStateExceptiononce the database is closed.Two cases:
close()cancels Room's internal scope before the newIllegalStateExceptioncan fire, so the query surfaces aCancellationExceptioninstead, and pinning the type would break on either side of that race.Flowcollector 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.