Skip to content

Commit

Permalink
Merge pull request #609 from uber/tys/coroutines-1.7
Browse files Browse the repository at this point in the history
Update coroutines 1.7.3
  • Loading branch information
tyvsmith authored Aug 23, 2023
2 parents 31f4984 + fa39761 commit f88e1fe
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 26 deletions.
4 changes: 2 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ 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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) {
}

@Test
fun bind_onStartIsCalledEagerly() {
fun bind_onStartIsCalledEagerly() = runTest {
val interactor = object : Interactor<Any, Router<*>>() {}
var onStartCalled = false
val worker = Worker { onStartCalled = true }
Expand All @@ -148,7 +148,7 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) {
}

@Test
fun bind_whenSubscribeToLifecycleInWorker_observerIsCalledEagerly() {
fun bind_whenSubscribeToLifecycleInWorker_observerIsCalledEagerly() = runTest {
val interactor = object : Interactor<Any, Router<*>>() {}
var enteredUnconfined = false
val worker = Worker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
*/
package com.uber.rib.core

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.CoroutineDispatcher
import org.junit.rules.TestWatcher
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() {

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!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand All @@ -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() =
Expand All @@ -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) }

Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit f88e1fe

Please sign in to comment.