Improved the DownloadTest which sometimes failing on API level 25

This commit is contained in:
MohitMaliFtechiz 2024-11-08 16:45:43 +05:30
parent f3d115cde1
commit 3c378b5d7a
2 changed files with 11 additions and 5 deletions

View File

@ -42,6 +42,7 @@ import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.string import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST
import org.kiwix.kiwixmobile.testutils.TestUtils import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
@ -150,12 +151,12 @@ class DownloadRobot : BaseRobot() {
fun waitUntilDownloadComplete(retryCountForDownloadingZimFile: Int = 30) { fun waitUntilDownloadComplete(retryCountForDownloadingZimFile: Int = 30) {
try { try {
onView(withId(R.id.stop)).check(doesNotExist()) onView(withId(R.id.stop)).check(doesNotExist())
Log.i("kiwixDownloadTest", "Download complete") Log.e(KIWIX_DOWNLOAD_TEST, "Download complete")
} catch (e: AssertionFailedError) { } catch (e: AssertionFailedError) {
if (retryCountForDownloadingZimFile > 0) { if (retryCountForDownloadingZimFile > 0) {
resumeDownloadIfPaused() resumeDownloadIfPaused()
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong()) BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
Log.i("kiwixDownloadTest", "Downloading in progress") Log.e(KIWIX_DOWNLOAD_TEST, "Downloading in progress")
waitUntilDownloadComplete(retryCountForDownloadingZimFile - 1) waitUntilDownloadComplete(retryCountForDownloadingZimFile - 1)
return return
} }
@ -203,7 +204,7 @@ class DownloadRobot : BaseRobot() {
pauseForBetterTestPerformance() pauseForBetterTestPerformance()
} catch (e: Exception) { } catch (e: Exception) {
Log.i( Log.i(
"DOWNLOAD_TEST", KIWIX_DOWNLOAD_TEST,
"Failed to stop downloading. Probably because it is not downloading the zim file" "Failed to stop downloading. Probably because it is not downloading the zim file"
) )
} }

View File

@ -17,6 +17,7 @@
*/ */
package org.kiwix.kiwixmobile.download package org.kiwix.kiwixmobile.download
import android.util.Log
import androidx.core.content.edit import androidx.core.content.edit
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
@ -138,17 +139,21 @@ class DownloadTest : BaseActivityTest() {
scrollToZimFileIndex(smallestZimFileIndex) scrollToZimFileIndex(smallestZimFileIndex)
stopDownloadIfAlreadyStarted() stopDownloadIfAlreadyStarted()
downloadZimFile(smallestZimFileIndex) downloadZimFile(smallestZimFileIndex)
assertDownloadStart()
try { try {
assertDownloadStart()
pauseDownload() pauseDownload()
assertDownloadPaused() assertDownloadPaused()
resumeDownload() resumeDownload()
assertDownloadResumed() assertDownloadResumed()
waitUntilDownloadComplete()
} catch (ignore: Exception) { } catch (ignore: Exception) {
// do nothing as ZIM file already downloaded, since we are downloading the smallest file // do nothing as ZIM file already downloaded, since we are downloading the smallest file
// so it can be downloaded immediately after starting. // so it can be downloaded immediately after starting.
Log.e(
KIWIX_DOWNLOAD_TEST,
"Could not pause download. Original exception = $ignore"
)
} }
waitUntilDownloadComplete()
clickLibraryOnBottomNav() clickLibraryOnBottomNav()
// refresh the local library list to show the downloaded zim file // refresh the local library list to show the downloaded zim file
library(LibraryRobot::refreshList) library(LibraryRobot::refreshList)