realm-java
realm-java copied to clipboard
Better ability to completely reset Sync tests
Fallout from #4760
Right now it is rather hard to do a full reset of tests involving synchronized Realms as it involves calling both SyncManager.reset() and nulling out BaseRealm.applicationContext. This also means that artifacts on the filesystem are left behind after each sync test, which is a weird test failure waiting to happen.
We should expose one single method that would completely wipe all Realm instances + re-initialize everything correctly.
Perhaps something like:
Realm.resetAndInit(Context context); // package protected
it is much better to just pass a new temp dir to init the SyncManager.
Also, creating a JUnit4 Rule SyncManagerRule to handle those may look cleaner and better.
It is more than just creating a dir, e.g Sync has some codepaths that are not touched until certain variables are reset. Same with Realm.init() .. This is also being tracked here: https://github.com/realm/realm-object-store/issues/207
Example. If you don't set BaseRealm.applicationContext = null, calling Realm.init() multiple times does nothing, and if you don't reset Object Store users, the filesystem folders and the meta Realms used by Object Store will not be re-created.