From a586ee6b14b6a0b33f26fa40eb21f7d548ed9cf0 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 14 Feb 2024 10:40:01 -0300 Subject: [PATCH] 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. --- .../stevesoltys/seedvault/e2e/LargeBackupTestBase.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/e2e/LargeBackupTestBase.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/e2e/LargeBackupTestBase.kt index f4537cd2..82d2e492 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/e2e/LargeBackupTestBase.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/e2e/LargeBackupTestBase.kt @@ -119,9 +119,21 @@ internal interface LargeBackupTestBase : LargeTestBase { coEvery { spyKVBackup.finishBackup() } answers { + val oldMap = HashMap() + // @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()