Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e14aba82 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

test(app): isolate Robolectric startup from install runtime

parent b8a33ec8
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -92,13 +92,6 @@ class AppLoungeApplication : Application(), Configuration.Provider {

        registerReceiver(pkgManagerBR, appLoungePackageManager.getFilter(), RECEIVER_EXPORTED)

        coroutineScope.launch {
            val currentVersion = sessionRepository.awaitTosVersion()
            if (!currentVersion.contentEquals(TOS_VERSION)) {
                sessionRepository.saveTocStatus(false, "")
            }
        }

        if (BuildConfig.DEBUG) {
            plant(Timber.DebugTree())
        } else {
@@ -118,6 +111,17 @@ class AppLoungeApplication : Application(), Configuration.Provider {
            })
        }

        // Robolectric eagerly creates the real Application for many unrelated unit tests.
        // Skip runtime startup jobs there to avoid leaking WorkManager/Room/DataStore work
        // across otherwise isolated tests.
        if (!isRunningUnderRobolectric()) {
            coroutineScope.launch {
                val currentVersion = sessionRepository.awaitTosVersion()
                if (!currentVersion.contentEquals(TOS_VERSION)) {
                    sessionRepository.saveTocStatus(false, "")
                }
            }

            coroutineScope.launch {
                migrateAnonymousUserUpdateIntervalUseCase()
                val updateInterval = getUpdateIntervalUseCase()
@@ -128,14 +132,10 @@ class AppLoungeApplication : Application(), Configuration.Provider {
                )
            }

        // Robolectric eagerly creates the real Application for many unrelated tests.
        // Skip install DB cleanup there to avoid background Room work leaking across tests.
        if (!isRunningUnderRobolectric()) {
            removeStalledInstallationFromDb()
        }

            installOrchestrator.init()
        }
    }

    private fun isRunningUnderRobolectric(): Boolean = Build.FINGERPRINT == "robolectric"