From c0bf8a8113d897973828d3f8bf5237cb63b9c4be Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 14:03:01 -0700 Subject: [PATCH 1/6] Update coroutines 1.7.3 --- android/gradle/libs.versions.toml | 4 ++-- .../kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt | 2 -- .../kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt | 4 +--- .../src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt | 6 ++++-- .../src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt | 2 -- .../kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt | 7 ------- .../main/kotlin/com/uber/rib/core/TestRibDispatchers.kt | 2 -- .../test/kotlin/com/uber/rib/core/RibCoroutinesRuleTest.kt | 2 -- .../test/kotlin/com/uber/rib/core/RibDispatchersTest.kt | 2 -- .../src/test/kotlin/com/uber/rib/core/RibScopesTest.kt | 2 -- 10 files changed, 7 insertions(+), 26 deletions(-) diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index 5b19dcca5..db0fa935e 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -13,7 +13,7 @@ compile-testing = "0.17" compose-compiler = "1.4.6" compose-libraries = "1.4.0" compose-navigation = "2.4.0-alpha03" -coroutines = "1.6.4" +coroutines = "1.7.3" dagger = "2.43.2" errorprone = "2.3.3" errorprone-javac = "9+181-r4173-1" @@ -33,7 +33,7 @@ javapoet = "1.11.1" jsr250 = "1.0" junit = "4.12" kotlin = "1.8.20" -kotlinx-coroutines = "1.6.4" +kotlinx-coroutines = "1.7.3" ktfmt = "0.43" ktlint = "0.48.2" leakcanary = "1.5.4" diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt index dde6f6e64..5ce172019 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt @@ -17,7 +17,6 @@ package com.uber.rib.core import com.google.common.truth.Truth.assertThat import io.reactivex.Observable -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.produce import kotlinx.coroutines.channels.toList import kotlinx.coroutines.launch @@ -25,7 +24,6 @@ import kotlinx.coroutines.test.runTest import org.junit.Test import org.mockito.kotlin.mock -@OptIn(ExperimentalCoroutinesApi::class) class LazyBackingPropertyTest { @Volatile private var _expensiveObject: ExpensiveObject? = null private val expensiveObject diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt index 13a77f6db..3b3e51406 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt @@ -24,7 +24,6 @@ import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Delay import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.Runnable import kotlinx.coroutines.awaitCancellation @@ -49,7 +48,6 @@ import org.junit.Test private const val ON_START_DELAY_DURATION_MILLIS = 100L -@OptIn(ExperimentalCoroutinesApi::class) class RibCoroutineWorkerTest { @get:Rule val coroutineRule = RibCoroutinesRule() private val worker = TestRibCoroutineWorker() @@ -180,7 +178,7 @@ class RibCoroutineWorkerTest { } } -@OptIn(ExperimentalCoroutinesApi::class, InternalCoroutinesApi::class) +@OptIn(InternalCoroutinesApi::class) private class ImmediateDispatcher( scheduler: TestCoroutineScheduler, private val delegate: TestDispatcher = StandardTestDispatcher(scheduler), diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt index f49f31969..709ba2f4e 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Before +import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -138,7 +139,7 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { } @Test - fun bind_onStartIsCalledEagerly() { + fun bind_onStartIsCalledEagerly() = runTest { val interactor = object : Interactor>() {} var onStartCalled = false val worker = Worker { onStartCalled = true } @@ -148,7 +149,8 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { } @Test - fun bind_whenSubscribeToLifecycleInWorker_observerIsCalledEagerly() { + @Ignore("Failing silently before Coroutines 1.7, to be investigated") + fun bind_whenSubscribeToLifecycleInWorker_observerIsCalledEagerly() = runTest { val interactor = object : Interactor>() {} var enteredUnconfined = false val worker = Worker { diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt index aa9b6a2e2..8f052d4af 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt @@ -15,7 +15,6 @@ */ package com.uber.rib.core -import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.rules.TestWatcher import org.junit.runner.Description @@ -23,7 +22,6 @@ import org.junit.runner.Description * RibCoroutinesRule is a Junit TestRule to act as a managed TestCoroutineScope in test and to * facilitate install and cleanup of Test Dispatchers */ -@ExperimentalCoroutinesApi public class RibCoroutinesRule( public val ribDispatchers: TestRibDispatchers = TestRibDispatchers(), ) : TestWatcher() { diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt index 50215cac1..237be9976 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt @@ -23,12 +23,10 @@ import com.uber.autodispose.coroutinesinterop.autoDispose import io.reactivex.Completable import io.reactivex.CompletableSource import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.test.TestScope -@ExperimentalCoroutinesApi /** returns the [TestScope] override currently installed for testing. */ public val ScopeProvider.testScopeOverride: TestScope? // Due to custom friend path usage, reference to LazyCoroutineScope will stay red in IDE @@ -42,7 +40,6 @@ public val ScopeProvider.testScopeOverride: TestScope? * Overrides [ScopeProvider.coroutineScope] with a [TestScope] with lifecycle integration for * testing. Accessible directly as [TestScope] via [ScopeProvider.TestScopeOverride]. */ -@ExperimentalCoroutinesApi public fun ScopeProvider.enableTestScopeOverride( context: CoroutineContext = SupervisorJob(), ): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = asTestScope(context) } @@ -52,7 +49,6 @@ public fun ScopeProvider.disableTestScopeOverride(): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = null } /** returns the [TestScope] override currently installed for testing. */ -@ExperimentalCoroutinesApi public val Application.testScopeOverride: TestScope? // Due to custom friend path usage, reference to LazyCoroutineScope will stay red in IDE get() = @@ -65,7 +61,6 @@ public val Application.testScopeOverride: TestScope? * Overrides [ScopeProvider.coroutineScope] with a [TestScope] with lifecycle integration for * testing. Accessible directly as [TestScope] via [ScopeProvider.TestScopeOverride]. */ -@ExperimentalCoroutinesApi public fun Application.enableTestScopeOverride(context: CoroutineContext = SupervisorJob()): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = TestScope(context) } @@ -74,13 +69,11 @@ public fun Application.disableTestScopeOverride(): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = null } /** Returns a new [TestScope] from the [ScopeProvider] */ -@ExperimentalCoroutinesApi public fun ScopeProvider.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope { return requestScope().asTestScope(context) } /** Returns a new [TestScope] from the [CompletableSource] */ -@ExperimentalCoroutinesApi public fun CompletableSource.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope { val scope = TestScope(context) Completable.wrap(this).autoDispose(scope).subscribe({ scope.cancel() }) { e -> diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibDispatchers.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibDispatchers.kt index 9a4eef459..4e52f80b8 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibDispatchers.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibDispatchers.kt @@ -16,7 +16,6 @@ package com.uber.rib.core import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.MainCoroutineDispatcher import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestCoroutineScheduler @@ -25,7 +24,6 @@ import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.setMain -@ExperimentalCoroutinesApi public data class TestRibDispatchers( /** * [TestCoroutineScheduler] to be used by all other [TestDispatcher] when using the default diff --git a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibCoroutinesRuleTest.kt b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibCoroutinesRuleTest.kt index c2c273a7c..b86786c83 100644 --- a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibCoroutinesRuleTest.kt +++ b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibCoroutinesRuleTest.kt @@ -16,7 +16,6 @@ package com.uber.rib.core import com.google.common.truth.Truth.assertThat -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.test.advanceTimeBy @@ -25,7 +24,6 @@ import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test -@OptIn(ExperimentalCoroutinesApi::class) class RibCoroutinesRuleTest { @get:Rule val ribCoroutinesRule = RibCoroutinesRule() diff --git a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibDispatchersTest.kt b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibDispatchersTest.kt index 9641e364f..c19c8d985 100644 --- a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibDispatchersTest.kt +++ b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibDispatchersTest.kt @@ -17,11 +17,9 @@ package com.uber.rib.core import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import org.junit.Test -@OptIn(ExperimentalCoroutinesApi::class) internal class RibDispatchersTest { @Test diff --git a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt index 7d79ab35e..16917843f 100644 --- a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt +++ b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt @@ -19,7 +19,6 @@ import android.app.Application import com.google.common.truth.Truth.assertThat import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineExceptionHandler -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch @@ -29,7 +28,6 @@ import org.junit.Rule import org.junit.Test import org.mockito.kotlin.mock -@OptIn(ExperimentalCoroutinesApi::class) internal class RibScopesTest { @get:Rule var rule = RibCoroutinesRule() From 09a08e634dd0d6b179ded16b23592f2eec832542 Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 14:10:02 -0700 Subject: [PATCH 2/6] Fixing test and removing ignore --- .../src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt index 709ba2f4e..c46d3adef 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt @@ -32,7 +32,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -64,6 +63,8 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { @Before fun setUp() { RibEvents.enableRibActionEmissions() + RibCoroutinesConfig.deprecatedWorkerDispatcher = ribCoroutinesRule.ribDispatchers.Unconfined + } @Test @@ -149,7 +150,6 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { } @Test - @Ignore("Failing silently before Coroutines 1.7, to be investigated") fun bind_whenSubscribeToLifecycleInWorker_observerIsCalledEagerly() = runTest { val interactor = object : Interactor>() {} var enteredUnconfined = false From 24e3ae7871f74a701a977918f647acf8bd2da463 Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 14:10:46 -0700 Subject: [PATCH 3/6] Fix spotless --- .../src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt index c46d3adef..c3cb9ac53 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt @@ -64,7 +64,6 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { fun setUp() { RibEvents.enableRibActionEmissions() RibCoroutinesConfig.deprecatedWorkerDispatcher = ribCoroutinesRule.ribDispatchers.Unconfined - } @Test From 25b8aaf2766179a2d2125ee56d9696ae100ad798 Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 14:33:16 -0700 Subject: [PATCH 4/6] Setting worker dispatcher in test rule --- .../src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt | 1 - .../src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt index c3cb9ac53..a75f0983c 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt @@ -63,7 +63,6 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { @Before fun setUp() { RibEvents.enableRibActionEmissions() - RibCoroutinesConfig.deprecatedWorkerDispatcher = ribCoroutinesRule.ribDispatchers.Unconfined } @Test diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt index 8f052d4af..f11e2fadf 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt @@ -26,11 +26,14 @@ public class RibCoroutinesRule( public val ribDispatchers: TestRibDispatchers = TestRibDispatchers(), ) : TestWatcher() { + private var originalDeprecatedWorkerDispatcher = RibCoroutinesConfig.deprecatedWorkerDispatcher override fun starting(description: Description) { ribDispatchers.installTestDispatchers() + RibCoroutinesConfig.deprecatedWorkerDispatcher = ribDispatchers.Unconfined } override fun finished(description: Description) { ribDispatchers.resetTestDispatchers() + RibCoroutinesConfig.deprecatedWorkerDispatcher = originalDeprecatedWorkerDispatcher } } From a6e2109c2913152378bcb1d32fe452ccd0c1264f Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 15:06:23 -0700 Subject: [PATCH 5/6] addressing feedback --- .../src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt index f11e2fadf..6dbfd01a7 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt @@ -15,6 +15,7 @@ */ package com.uber.rib.core +import kotlinx.coroutines.CoroutineDispatcher import org.junit.rules.TestWatcher import org.junit.runner.Description @@ -26,14 +27,15 @@ public class RibCoroutinesRule( public val ribDispatchers: TestRibDispatchers = TestRibDispatchers(), ) : TestWatcher() { - private var originalDeprecatedWorkerDispatcher = RibCoroutinesConfig.deprecatedWorkerDispatcher + private var originalDeprecatedWorkerDispatcher : CoroutineDispatcher? = null override fun starting(description: Description) { ribDispatchers.installTestDispatchers() + originalDeprecatedWorkerDispatcher = RibCoroutinesConfig.deprecatedWorkerDispatcher RibCoroutinesConfig.deprecatedWorkerDispatcher = ribDispatchers.Unconfined } override fun finished(description: Description) { ribDispatchers.resetTestDispatchers() - RibCoroutinesConfig.deprecatedWorkerDispatcher = originalDeprecatedWorkerDispatcher + RibCoroutinesConfig.deprecatedWorkerDispatcher = originalDeprecatedWorkerDispatcher!! } } From fa39761edbee49bceb09e06fa98098e0f1990975 Mon Sep 17 00:00:00 2001 From: tys Date: Tue, 22 Aug 2023 15:07:08 -0700 Subject: [PATCH 6/6] Spotless --- .../src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt index 6dbfd01a7..af0671684 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt @@ -27,7 +27,7 @@ public class RibCoroutinesRule( public val ribDispatchers: TestRibDispatchers = TestRibDispatchers(), ) : TestWatcher() { - private var originalDeprecatedWorkerDispatcher : CoroutineDispatcher? = null + private var originalDeprecatedWorkerDispatcher: CoroutineDispatcher? = null override fun starting(description: Description) { ribDispatchers.installTestDispatchers() originalDeprecatedWorkerDispatcher = RibCoroutinesConfig.deprecatedWorkerDispatcher