Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Dec 7, 2022
1 parent dcbdb54 commit ac5cf99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions docs/database_migration_test.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<!--- TOC -->

* [Testing database migration](#testing-database-migration)
* [Creating a reference database](#creating-a-reference-database)
* [Testing](#testing)

<!--- END -->

## Testing database migration

### Creating a reference database

Databases are encrypted, the key to decrypt is needed to setup the test.
A special build property must be enabled to extract it.

Set `vector.debugPrivateData=true` in `gradle.properties`
Set `vector.debugPrivateData=true` in `~/.gradle/gradle.properties` (to avoid committing by mistake)

Launch the app in your emulator, login and use the app to feel up the database.
Launch the app in your emulator, login and use the app to fill up the database.

Save the key for the tested database
```
Expand All @@ -20,8 +28,8 @@ Use the [Device File Explorer](https://developer.android.com/studio/debug/device

Go to `data/data/im.vector.app.debug/files/<hash>/`
Pick the database you want to test (name can be found in SessionRealmConfigurationFactory):
- crypto_store.real for crypto
- disk_store for session
- crypto_store.realm for crypto
- disk_store.realm for session
- etc...

Download the file on your disk
Expand All @@ -33,7 +41,7 @@ Copy the file in `src/AndroidTest/assets`
see `CryptoSanityMigrationTest` or `RealmSessionStoreMigration43Test` for sample tests.

There are already some databases in the assets folder.
The existing test will properly detect schema changes, and fail with such errors:
The existing test will properly detect schema changes, and fail with such errors if a migration is missing:

```
io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CryptoSanityMigrationTest {
val realmName = "crypto_store_20.realm"
val migration = RealmCryptoStoreMigration(object : Clock {
override fun epochMillis(): Long {
return System.currentTimeMillis()
return 0L
}
})
val realmConfiguration = configurationFactory.createConfiguration(
Expand Down

0 comments on commit ac5cf99

Please sign in to comment.