Skip to content

Commit

Permalink
Upgrade coroutines to 1.6.1
Browse files Browse the repository at this point in the history
And update usages according to migratino guide.
  • Loading branch information
steve-the-edwards committed Jul 18, 2022
1 parent d19ae7a commit d916348
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 136 deletions.
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ kotest = "5.1.0"
kotlin = "1.6.10"

kotlinx-binary-compatibility = "0.6.0"
kotlinx-coroutines = "1.5.1"
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
kotlinx-coroutines-test-common = "1.6.1"
kotlinx-coroutines = "1.6.4"
kotlinx-serialization-json = "1.3.2"
kotlinx-benchmark = "0.4.2"
kotlinx-atomicfu = "0.17.2"
Expand Down Expand Up @@ -187,7 +185,7 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test-common = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines-test-common" }
kotlinx-coroutines-test-common = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
kotlinx-benchmark-gradle-plugin = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref = "kotlinx-benchmark" }
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
Expand Down
5 changes: 3 additions & 2 deletions trace-encoder/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
5 changes: 3 additions & 2 deletions workflow-config/config-jvm/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
5 changes: 3 additions & 2 deletions workflow-core/dependencies/jvmRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ org.jetbrains.kotlin:kotlin-bom:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
5 changes: 3 additions & 2 deletions workflow-core/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
5 changes: 3 additions & 2 deletions workflow-runtime/dependencies/jvmRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ org.jetbrains.kotlin:kotlin-bom:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class RenderWorkflowInTest {
if (runtimeConfig1 is FrameTimeout) {
// Get past frame timeout to ensure snapshot saved.
testScope.advanceTimeBy(runtimeConfig1.frameTimeoutMs + 1)
testScope.runCurrent()
}
val snapshot = renderings.value.let { (rendering, snapshot) ->
val (state, updateState) = rendering
Expand Down Expand Up @@ -280,13 +281,15 @@ class RenderWorkflowInTest {
if (runtimeConfig is FrameTimeout) {
// Get past frame timeout to ensure snapshot saved.
testScope.advanceTimeBy(runtimeConfig.frameTimeoutMs + 1)
testScope.runCurrent()
}

sink.send("unchanging state")

if (runtimeConfig is FrameTimeout) {
// Get past frame timeout to ensure snapshot saved.
testScope.advanceTimeBy(runtimeConfig.frameTimeoutMs + 1)
testScope.runCurrent()
}

scope.cancel()
Expand Down Expand Up @@ -506,6 +509,7 @@ class RenderWorkflowInTest {
trigger.complete(Unit)
if (runtimeConfig is FrameTimeout) {
testScope.advanceTimeBy(runtimeConfig.frameTimeoutMs + 1)
testScope.runCurrent()
}
assertFalse(testScope.isActive)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION")
@file:OptIn(ExperimentalCoroutinesApi::class)

package com.squareup.workflow1.internal

Expand Down Expand Up @@ -29,12 +30,13 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.Unconfined
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.selects.select
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.test.AfterTest
Expand Down Expand Up @@ -173,14 +175,14 @@ internal class WorkflowNodeTest {
)
node.render(workflow, "")("event")

val result = runBlocking {
withTimeout(10) {
runTest {
val result = withTimeout(10) {
select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
}
assertEquals("tick:event", result?.value)
}
assertEquals("tick:event", result?.value)
}

@Test fun `accepts events sent to stale renderings`() {
Expand Down Expand Up @@ -210,16 +212,16 @@ internal class WorkflowNodeTest {
sink("event")
sink("event2")

val result = runBlocking {
withTimeout(10) {
runTest {
val result = withTimeout(10) {
List(2) {
select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
}
}
assertEquals(listOf("tick:event", "tick:event2"), result.map { it?.value })
}
assertEquals(listOf("tick:event", "tick:event2"), result.map { it?.value })
}

@Test fun `send allows subsequent events on same rendering`() {
Expand Down Expand Up @@ -264,7 +266,7 @@ internal class WorkflowNodeTest {
snapshot = null, baseContext = context
)

runBlocking {
runTest {
node.render(workflow.asStatefulWorkflow(), Unit)
assertTrue(started)
}
Expand Down Expand Up @@ -302,16 +304,15 @@ internal class WorkflowNodeTest {
)
node.render(workflow.asStatefulWorkflow(), Unit)

val result = runBlocking {
runTest {
// Result should be available instantly, any delay at all indicates something is broken.
withTimeout(1) {
val result = withTimeout(1) {
select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
}
assertEquals("result", result?.value)
}

assertEquals("result", result?.value)
}

@Test fun `sideEffect is cancelled when stops being ran`() {
Expand All @@ -331,7 +332,7 @@ internal class WorkflowNodeTest {
snapshot = null, baseContext = context
)

runBlocking {
runTest {
node.render(workflow.asStatefulWorkflow(), true)
assertNull(cancellationException)

Expand All @@ -357,7 +358,7 @@ internal class WorkflowNodeTest {
snapshot = null, baseContext = context
)

runBlocking {
runTest {
node.render(workflow.asStatefulWorkflow(), Unit)
assertNull(cancellationException)

Expand All @@ -383,7 +384,7 @@ internal class WorkflowNodeTest {
snapshot = null, baseContext = context
)

runBlocking {
runTest {
node.render(workflow.asStatefulWorkflow(), 0)
assertFalse(cancelled)
assertEquals(1, renderPasses)
Expand All @@ -408,7 +409,7 @@ internal class WorkflowNodeTest {
snapshot = null, baseContext = context
)

runBlocking {
runTest {
node.render(workflow.asStatefulWorkflow(), 0)
assertEquals(listOf(0), seenProps)
assertEquals(1, renderPasses)
Expand Down Expand Up @@ -1099,7 +1100,7 @@ internal class WorkflowNodeTest {

sink.send("hello")

runBlocking {
runTest {
select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
Expand All @@ -1125,13 +1126,12 @@ internal class WorkflowNodeTest {

rendering.send("hello")

val output = runBlocking {
select<ActionProcessingResult?> {
runTest {
val output = select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
assertEquals("output:hello", output?.value)
}

assertEquals("output:hello", output?.value)
}

@Test fun `actionSink action allows null output`() {
Expand All @@ -1150,13 +1150,12 @@ internal class WorkflowNodeTest {

rendering.send("hello")

val output = runBlocking {
select<ActionProcessingResult?> {
runTest {
val output = select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
assertNull(output?.value)
}

assertNull(output?.value)
}

@Test fun `child action changes state`() {
Expand All @@ -1178,7 +1177,7 @@ internal class WorkflowNodeTest {
)
node.render(workflow.asStatefulWorkflow(), Unit)

runBlocking {
runTest {
select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
Expand All @@ -1204,13 +1203,12 @@ internal class WorkflowNodeTest {
)
node.render(workflow.asStatefulWorkflow(), Unit)

val output = runBlocking {
select<ActionProcessingResult?> {
runTest {
val output = select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
assertEquals("output:child:hello", output?.value)
}

assertEquals("output:child:hello", output?.value)
}

@Test fun `child action allows null output`() {
Expand All @@ -1229,13 +1227,12 @@ internal class WorkflowNodeTest {
)
node.render(workflow.asStatefulWorkflow(), Unit)

val output = runBlocking {
select<ActionProcessingResult?> {
runTest {
val output = select<ActionProcessingResult?> {
node.tick(this)
} as WorkflowOutput<String>?
assertNull(output?.value)
}

assertNull(output?.value)
}

private class TestSession(override val sessionId: Long = 0) : WorkflowSession {
Expand Down
9 changes: 5 additions & 4 deletions workflow-rx2/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.6.1
org.jetbrains:annotations:13.0
org.reactivestreams:reactive-streams:1.0.3
11 changes: 5 additions & 6 deletions workflow-testing/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
:workflow-runtime
com.squareup.okio:okio-jvm:3.0.0
com.squareup.okio:okio:3.0.0
net.java.dev.jna:jna-platform:5.5.0
net.java.dev.jna:jna:5.5.0
org.jetbrains.kotlin:kotlin-bom:1.6.10
org.jetbrains.kotlin:kotlin-reflect:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:1.6.1
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1
org.jetbrains:annotations:13.0
Loading

0 comments on commit d916348

Please sign in to comment.