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

Commit d78ed361 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Reduce the flaky of SpaPrivilegedLibTests

SettingsGlobalChangeFlowTest
 - not checking the exact size of flow, which is not critical.

DisposableBroadcastReceiverAsUserTest
 - add some delay

Bug: 288353352
Test: unit test
Change-Id: Ic4cbff40fcc93c8cf11c30b3b896285bf5626253
parent b67dfbd3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -27,9 +27,8 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.lifecycle.testing.TestLifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settingslib.spa.testutils.delay
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -72,12 +71,13 @@ class DisposableBroadcastReceiverAsUserTest {
                DisposableBroadcastReceiverAsUser(INTENT_FILTER, USER_HANDLE) {}
            }
        }
        composeTestRule.delay()

        assertThat(registeredBroadcastReceiver).isNotNull()
    }

    @Test
    fun broadcastReceiver_isCalledOnReceive() = runBlocking {
    fun broadcastReceiver_isCalledOnReceive() {
        var onReceiveIsCalled = false
        composeTestRule.setContent {
            CompositionLocalProvider(
@@ -91,7 +91,7 @@ class DisposableBroadcastReceiverAsUserTest {
        }

        registeredBroadcastReceiver!!.onReceive(context, Intent())
        delay(100)
        composeTestRule.delay()

        assertThat(onReceiveIsCalled).isTrue()
    }
+2 −13
Original line number Diff line number Diff line
@@ -48,18 +48,7 @@ class SettingsGlobalChangeFlowTest {
    }

    @Test
    fun settingsGlobalChangeFlow_collectAfterValueChanged_onlyKeepLatest() = runBlocking {
        var value by context.settingsGlobalBoolean(TEST_NAME)
        value = false

        val flow = context.settingsGlobalChangeFlow(TEST_NAME)
        value = true

        assertThat(flow.toListWithTimeout()).hasSize(1)
    }

    @Test
    fun settingsGlobalChangeFlow_collectBeforeValueChanged_getBoth() = runBlocking {
    fun settingsGlobalChangeFlow_changed() = runBlocking {
        var value by context.settingsGlobalBoolean(TEST_NAME)
        value = false

@@ -69,7 +58,7 @@ class SettingsGlobalChangeFlowTest {
        delay(100)
        value = true

        assertThat(listDeferred.await()).hasSize(2)
        assertThat(listDeferred.await().size).isAtLeast(2)
    }

    private companion object {