From 4dd64f3676a5996d073c34e305c1cc54f9edb792 Mon Sep 17 00:00:00 2001 From: Alejandro Nijamkin Date: Wed, 26 Jul 2023 16:14:53 -0700 Subject: [PATCH] Fixes failing test after coroutine lib upgrade. The changed test case started failing after the coroutines library has been upgraded; not sure why. This fixes it by adding an additional runCurrent() right after collectLastValue is called. This gives an opportunity for the upstream conflatedCallbackFlow to do its work and register its callback. When the value is queried in the assertion line, collectLastValue runs its own runCurrent() to trigger any pending coroutines, updating the value that the test sees. Bug: 292807808 Test: N/A Change-Id: If42e96e9ae29ae6e0585f6c2b567cca7b15d581e Merged-In: If42e96e9ae29ae6e0585f6c2b567cca7b15d581e (cherry picked from commit 2964de1d655fb33d359209329b82cbe899f31cad) --- .../data/repository/RetailModeSettingsRepositoryTest.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/SystemUI/tests/src/com/android/systemui/retail/data/repository/RetailModeSettingsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/retail/data/repository/RetailModeSettingsRepositoryTest.kt index d7682b20a98de..421c355950264 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/retail/data/repository/RetailModeSettingsRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/retail/data/repository/RetailModeSettingsRepositoryTest.kt @@ -26,6 +26,7 @@ import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith @@ -51,6 +52,7 @@ class RetailModeSettingsRepositoryTest : SysuiTestCase() { fun retailMode_defaultFalse() = testScope.runTest { val value by collectLastValue(underTest.retailMode) + runCurrent() assertThat(value).isFalse() assertThat(underTest.inRetailMode).isFalse() @@ -60,6 +62,7 @@ class RetailModeSettingsRepositoryTest : SysuiTestCase() { fun retailMode_false() = testScope.runTest { val value by collectLastValue(underTest.retailMode) + runCurrent() globalSettings.putInt(SETTING, 0) @@ -71,6 +74,7 @@ class RetailModeSettingsRepositoryTest : SysuiTestCase() { fun retailMode_true() = testScope.runTest { val value by collectLastValue(underTest.retailMode) + runCurrent() globalSettings.putInt(SETTING, 1)