Add test to reproduce the loading cursor phenomena with Nextcloud

See: https://commonsware.com/blog/2019/12/14/scoped-storage-stories-listfiles-woe.html
This commit is contained in:
Torsten Grote 2020-08-06 16:43:15 -03:00 committed by Chirayu Desai
parent 22aaaeb1fd
commit 131c5b6b29

View file

@ -62,6 +62,47 @@ class PluginTest : KoinComponent {
assertNotNull(backupPlugin.providerPackageName)
}
/**
* This test initializes the storage three times while creating two new restore sets.
*
* If this is run against a Nextcloud storage backend,
* it has a high chance of getting a loading cursor in the underlying queries
* that needs to get re-queried to get real results.
*/
@Test
fun testInitializationAndRestoreSets() {
// no backups available initially
assertEquals(0, restorePlugin.getAvailableBackups()?.toList()?.size)
val uri = settingsManager.getStorage()?.getDocumentFile(context)?.uri ?: error("no storage")
assertFalse(restorePlugin.hasBackup(uri))
// define storage changing state for later
every {
mockedSettingsManager.getAndResetIsStorageChanging()
} returns true andThen true andThen false
// device needs initialization, because new and storage is changing
assertTrue(backupPlugin.initializeDevice(newToken = token))
// write metadata (needed for backup to be recognized)
backupPlugin.getMetadataOutputStream().writeAndClose(getRandomByteArray())
// one backup available now
assertEquals(1, restorePlugin.getAvailableBackups()?.toList()?.size)
assertTrue(restorePlugin.hasBackup(uri))
// initializing again (while changing storage) does add a restore set
assertTrue(backupPlugin.initializeDevice(newToken = token + 1))
backupPlugin.getMetadataOutputStream().writeAndClose(getRandomByteArray())
assertEquals(2, restorePlugin.getAvailableBackups()?.toList()?.size)
assertTrue(restorePlugin.hasBackup(uri))
// initializing again (without changing storage) doesn't change number of restore sets
assertFalse(backupPlugin.initializeDevice(newToken = token + 2))
backupPlugin.getMetadataOutputStream().writeAndClose(getRandomByteArray())
assertEquals(2, restorePlugin.getAvailableBackups()?.toList()?.size)
}
@Test
fun testMetadataWriteRead() {
every { mockedSettingsManager.getAndResetIsStorageChanging() } returns true andThen false