From 9eabc830c0ab600ab81dec431528e2b469f04459 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 21 Oct 2024 22:43:49 +0200 Subject: [PATCH] Fix flaky tests. --- .../impl/developer/DeveloperSettingsPresenterTest.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt index 51750d4bfb..5568b2beba 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt @@ -26,8 +26,9 @@ import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore import io.element.android.tests.testutils.WarmUpRule import io.element.android.tests.testutils.awaitLastSequentialItem import io.element.android.tests.testutils.lambda.lambdaRecorder -import kotlinx.coroutines.delay +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.first +import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test @@ -154,6 +155,7 @@ class DeveloperSettingsPresenterTest { } } + @OptIn(ExperimentalCoroutinesApi::class) @Test fun `present - toggling simplified sliding sync changes the preferences and logs out the user`() = runTest { val logoutCallRecorder = lambdaRecorder { "" } @@ -169,15 +171,13 @@ class DeveloperSettingsPresenterTest { initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(true)) assertThat(awaitItem().isSimpleSlidingSyncEnabled).isTrue() assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue() - // Give time for the logout to be called, but for some reason using runCurrent() is not enough - delay(2) + advanceUntilIdle() logoutCallRecorder.assertions().isCalledOnce() initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(false)) assertThat(awaitItem().isSimpleSlidingSyncEnabled).isFalse() assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse() - // Give time for the logout to be called, but for some reason using runCurrent() is not enough - delay(2) + advanceUntilIdle() logoutCallRecorder.assertions().isCalledExactly(times = 2) } }