In instrumentation tests, keep incremental backups

If we request backup in several chunks, packages like 'pm@' or 'android' get backed up for each chunk, so due to incremental backups, we need to keep old data when comparing.
This commit is contained in:
Torsten Grote 2024-02-14 10:40:01 -03:00
parent b47b4ade1e
commit a586ee6b14
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -119,9 +119,21 @@ internal interface LargeBackupTestBase : LargeTestBase {
coEvery {
spyKVBackup.finishBackup()
} answers {
val oldMap = HashMap<String, String>()
// @pm@ and android can get backed up multiple times (if we need more than one request)
// so we need to keep the data it backed up before
if (backupResult.kv.containsKey(packageName)) {
backupResult.kv[packageName]?.forEach { (key, value) ->
// if a key existing in new data, we use its value from new data, don't override
if (!data.containsKey(key)) oldMap[key] = value
}
}
backupResult.kv[packageName!!] = data
.mapValues { entry -> entry.value.sha256() }
.toMutableMap()
.apply {
putAll(oldMap)
}
packageName = null
data = mutableMapOf()