mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Improved ObjectBoxToLibkiwixMigratorTest and clearing the application data before running the test cases.
This commit is contained in:
parent
39930b844e
commit
29287df550
@ -257,44 +257,30 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
|
||||
@Test
|
||||
fun testLargeDataMigration(): Unit = runBlocking {
|
||||
// Test large data migration for recent searches
|
||||
val numEntities = 1000
|
||||
// Insert a large number of recent search entities into ObjectBox
|
||||
(1..numEntities)
|
||||
.asSequence()
|
||||
.map {
|
||||
for (i in 1..1000) {
|
||||
box.put(
|
||||
BookmarkEntity(
|
||||
0,
|
||||
expectedZimId,
|
||||
expectedZimName,
|
||||
expectedZimFilePath,
|
||||
"https://alpine_linux/search_$it",
|
||||
"title_$it",
|
||||
"https://alpine_linux/search_$i",
|
||||
"title_$i",
|
||||
expectedFavicon
|
||||
)
|
||||
}
|
||||
.forEach(box::put)
|
||||
withContext(Dispatchers.IO) {
|
||||
)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
// Migrate data into Room database
|
||||
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
|
||||
}
|
||||
// Check if data successfully migrated to Room
|
||||
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{ actualDataAfterMigration ->
|
||||
assertEquals(numEntities, actualDataAfterMigration.size)
|
||||
// Clear the bookmarks list from device to not affect the other test cases.
|
||||
clearBookmarks()
|
||||
},
|
||||
{
|
||||
// Clear the bookmarks list from device to not affect the other test cases.
|
||||
clearBookmarks()
|
||||
throw RuntimeException(
|
||||
"Exception occurred during migration. Original Exception ${it.printStackTrace()}"
|
||||
)
|
||||
}
|
||||
)
|
||||
val actualDataAfterMigration =
|
||||
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
|
||||
assertEquals(1000, actualDataAfterMigration.size)
|
||||
// Clear the bookmarks list from device to not affect the other test cases.
|
||||
clearBookmarks()
|
||||
}
|
||||
|
||||
private fun clearBookmarks() {
|
||||
|
@ -4,19 +4,7 @@ adb logcat -c
|
||||
# shellcheck disable=SC2035
|
||||
adb logcat *:E -v color &
|
||||
retry=0
|
||||
|
||||
|
||||
PACKAGE_NAME="org.kiwix.kiwixmobile"
|
||||
|
||||
# Function to check if the application is installed
|
||||
is_app_installed() {
|
||||
adb shell pm list packages | grep -q "${PACKAGE_NAME}"
|
||||
}
|
||||
|
||||
if is_app_installed; then
|
||||
# Clear application data to properly run the test cases.
|
||||
adb shell pm clear "${PACKAGE_NAME}"
|
||||
fi
|
||||
adb shell pm clear "org.kiwix.kiwixmobile"
|
||||
|
||||
while [ $retry -le 3 ]; do
|
||||
if ./gradlew jacocoInstrumentationTestReport; then
|
||||
@ -29,17 +17,7 @@ while [ $retry -le 3 ]; do
|
||||
# shellcheck disable=SC2035
|
||||
adb logcat *:E -v color &
|
||||
|
||||
PACKAGE_NAME="org.kiwix.kiwixmobile"
|
||||
|
||||
# Function to check if the application is installed
|
||||
is_app_installed() {
|
||||
adb shell pm list packages | grep -q "${PACKAGE_NAME}"
|
||||
}
|
||||
|
||||
if is_app_installed; then
|
||||
# Clear application data to properly run the test cases.
|
||||
adb shell pm clear "${PACKAGE_NAME}"
|
||||
fi
|
||||
adb shell pm clear "org.kiwix.kiwixmobile"
|
||||
./gradlew clean
|
||||
retry=$(( retry + 1 ))
|
||||
if [ $retry -eq 3 ]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user