Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the CI on api level 33 and reduce the CI timing. #3758

Merged
merged 12 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
ram-size: '4096M'
disk-size: '14G'
sdcard-path-or-size: ${{ matrix.api-level != 33 && '1000M' || '4096M' }}
disable-animations: false
disable-animations: true
heap-size: ${{ matrix.api-level == 33 && '512M' || '' }}
script: bash contrib/instrumentation.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import io.objectbox.Box
import io.objectbox.BoxStore
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
Expand Down Expand Up @@ -120,6 +116,9 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
}
box = boxStore.boxFor(BookmarkEntity::class.java)

// clear the data before running the test case
clearBookmarks()

// add a file in fileSystem because we need to actual file path for making object of Archive.
val loadFileStream =
ObjectBoxToLibkiwixMigratorTest::class.java.classLoader.getResourceAsStream("testzim.zim")
Expand All @@ -139,9 +138,6 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
}
}
}

// clear the data before running the test case
clearBookmarks()
}

@Test
Expand All @@ -162,49 +158,25 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedFavicon
)
box.put(bookmarkEntity)
withContext(Dispatchers.IO) {
// migrate data into room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
// 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(1, actualDataAfterMigration.size)
assertEquals(actualDataAfterMigration[0].zimFilePath, expectedZimFilePath)
assertEquals(actualDataAfterMigration[0].zimId, expectedZimId)
assertEquals(actualDataAfterMigration[0].title, expectedTitle)
assertEquals(actualDataAfterMigration[0].url, expectedBookmarkUrl)
},
{
throw RuntimeException(
"Exception occurred during migration. Original Exception ${it.printStackTrace()}"
)
}
)
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(1, actualDataAfterMigration.size)
assertEquals(actualDataAfterMigration[0].zimFilePath, expectedZimFilePath)
assertEquals(actualDataAfterMigration[0].zimId, expectedZimId)
assertEquals(actualDataAfterMigration[0].title, expectedTitle)
assertEquals(actualDataAfterMigration[0].url, expectedBookmarkUrl)
}

@Test
fun testMigrationWithEmptyData(): Unit = runBlocking {
withContext(Dispatchers.IO) {
// Migrate data from empty ObjectBox database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ actualDataAfterMigration ->
assertTrue(actualDataAfterMigration.isEmpty())
},
{
throw RuntimeException(
"Exception occurred during migration. Original Exception ${it.printStackTrace()}"
)
}
)
// Migrate data from empty ObjectBox database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertTrue(actualDataAfterMigration.isEmpty())
}

@Test
Expand All @@ -222,85 +194,54 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedFavicon
)
val libkiwixBook = Book()
withContext(Dispatchers.IO) {
objectBoxToLibkiwixMigrator.libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(
secondBookmarkEntity,
libkiwixBook
)
)
box.put(bookmarkEntity)
}
withContext(Dispatchers.IO) {
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
}
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ actualDataAfterMigration ->
assertEquals(2, actualDataAfterMigration.size)
val existingItem =
actualDataAfterMigration.find {
it.url == existingBookmarkUrl && it.title == existingTitle
}
assertNotNull(existingItem)
val newItem =
actualDataAfterMigration.find {
it.url == expectedBookmarkUrl && it.title == expectedTitle
}
assertNotNull(newItem)
},
{
throw RuntimeException(
"Exception occurred during migration. Original Exception ${it.printStackTrace()}"
)
}
objectBoxToLibkiwixMigrator.libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(
secondBookmarkEntity,
libkiwixBook
)
)
box.put(bookmarkEntity)
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(2, actualDataAfterMigration.size)
val existingItem =
actualDataAfterMigration.find {
it.url == existingBookmarkUrl && it.title == existingTitle
}
assertNotNull(existingItem)
val newItem =
actualDataAfterMigration.find {
it.url == expectedBookmarkUrl && it.title == expectedTitle
}
assertNotNull(newItem)
}

@Test
fun testLargeDataMigration(): Unit = runBlocking {
// Test large data migration for recent searches
val numEntities = 10000
// 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) {
// Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box)
)
}
// 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() {
Expand All @@ -310,7 +251,9 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
.blockingFirst() as List<LibkiwixBookmarkItem>
)
box.removeAll()
zimFile.delete() // delete the temp ZIM file to free up the memory
if (::zimFile.isInitialized) {
zimFile.delete() // delete the temp ZIM file to free up the memory
}
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fun downloadRobot(func: DownloadRobot.() -> Unit) =

class DownloadRobot : BaseRobot() {

private var retryCountForDataToLoad = 5
private var retryCountForCheckDownloadStart = 5
private var retryCountForDataToLoad = 10
private var retryCountForCheckDownloadStart = 10
private val zimFileTitle = "Off the Grid"

fun clickLibraryOnBottomNav() {
Expand All @@ -69,6 +69,10 @@ class DownloadRobot : BaseRobot() {
isVisible(Text(zimFileTitle))
}

fun refreshOnlineList() {
refresh(R.id.librarySwipeRefresh)
}

fun downloadZimFile() {
clickOn(Text(zimFileTitle))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.nav.destination.library.library
Expand Down Expand Up @@ -81,11 +82,11 @@ class DownloadTest : BaseActivityTest() {
@Test
fun downloadTest() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
activityScenario.onActivity {
it.navigate(R.id.libraryFragment)
}
try {
downloadRobot {
clickLibraryOnBottomNav()
refreshLocalLibraryData()
}
downloadRobot(DownloadRobot::refreshLocalLibraryData)
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
Expand All @@ -94,6 +95,7 @@ class DownloadTest : BaseActivityTest() {
}
downloadRobot {
clickDownloadOnBottomNav()
refreshOnlineList()
waitForDataToLoad()
stopDownloadIfAlreadyStarted()
downloadZimFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ fun initialDownload(func: InitialDownloadRobot.() -> Unit) =

class InitialDownloadRobot : BaseRobot() {

private var retryCountForCheckDownloadStart = 5
private var retryCountForCheckDataLoaded = 5
private var retryCountForCheckDownloadStart = 10
private var retryCountForCheckDataLoaded = 10
private val zimFileTitle = "Off the Grid"

fun clickLibraryOnBottomNav() {
clickOn(ViewId(R.id.libraryFragment))
}

fun clickDownloadOnBottomNav() {
clickOn(ViewId(R.id.downloadsFragment))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.nav.destination.library.library
Expand Down Expand Up @@ -74,10 +75,10 @@ class InitialDownloadTest : BaseActivityTest() {
@Test
fun initialDownloadTest() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
initialDownload {
clickLibraryOnBottomNav()
refreshLocalLibraryData()
activityScenario.onActivity {
it.navigate(R.id.libraryFragment)
}
initialDownload(InitialDownloadRobot::refreshLocalLibraryData)
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import android.Manifest
import android.app.Instrumentation
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
Expand All @@ -46,9 +47,6 @@ class LanguageFragmentTest {
@JvmField
var retryRule = RetryRule()

@get:Rule
var activityScenarioRule = ActivityScenarioRule(KiwixMainActivity::class.java)

private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
Expand Down Expand Up @@ -77,6 +75,9 @@ class LanguageFragmentTest {
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
putBoolean(SharedPreferenceUtil.PREF_PLAY_STORE_RESTRICTION, false)
}
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun language(func: LanguageRobot.() -> Unit) = LanguageRobot().applyWithViewHier

class LanguageRobot : BaseRobot() {

private var retryCountForDataToLoad = 5
private var retryCountForDataToLoad = 10

fun clickDownloadOnBottomNav() {
clickOn(ViewId(R.id.downloadsFragment))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class TopLevelDestinationTest : BaseActivityTest() {
topLevel {
clickReaderOnBottomNav {
}
clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed)
clickLibraryOnBottomNav {
assertGetZimNearbyDeviceDisplayed()
clickFileTransferIcon(LocalFileTransferRobot::assertReceiveFileTitleVisible)
}
clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed)
clickBookmarksOnNavDrawer {
assertBookMarksDisplayed()
clickOnTrashIcon()
Expand Down
Loading
Loading