Skip to content

Commit 16e9620

Browse files
Upgrade coroutines to 1.6.1
Still left todo: Udpate all uses of runBlocking in tests to use runTest where appropriate now that runTest handles asynchronous calls correctly.
1 parent 35d9232 commit 16e9620

File tree

20 files changed

+129
-126
lines changed

20 files changed

+129
-126
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ kotest = "5.1.0"
4949
kotlin = "1.6.10"
5050

5151
kotlinx-binary-compatibility = "0.6.0"
52-
kotlinx-coroutines = "1.5.1"
52+
kotlinx-coroutines = "1.6.1"
5353
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
5454
kotlinx-coroutines-test-common = "1.6.1"
5555
kotlinx-serialization-json = "1.3.2"

trace-encoder/dependencies/runtimeClasspath.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
66
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
77
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
88
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
9-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
10-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
9+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
10+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
11+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
1112
org.jetbrains:annotations:13.0

workflow-core/dependencies/jvmRuntimeClasspath.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ org.jetbrains.kotlin:kotlin-bom:1.6.10
44
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
55
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
66
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
7-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
8-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
7+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
8+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
9+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
910
org.jetbrains:annotations:13.0

workflow-core/dependencies/runtimeClasspath.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
55
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
66
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
77
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
8-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
9-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
8+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
9+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
10+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
1011
org.jetbrains:annotations:13.0

workflow-runtime/dependencies/jvmRuntimeClasspath.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ org.jetbrains.kotlin:kotlin-bom:1.6.10
55
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
66
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
77
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
8-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
9-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
8+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
9+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
10+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
1011
org.jetbrains:annotations:13.0

workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION")
2+
@file:OptIn(ExperimentalCoroutinesApi::class)
23

34
package com.squareup.workflow1.internal
45

@@ -28,12 +29,13 @@ import kotlinx.coroutines.CancellationException
2829
import kotlinx.coroutines.CoroutineName
2930
import kotlinx.coroutines.CoroutineScope
3031
import kotlinx.coroutines.Dispatchers.Unconfined
32+
import kotlinx.coroutines.ExperimentalCoroutinesApi
3133
import kotlinx.coroutines.Job
3234
import kotlinx.coroutines.cancel
3335
import kotlinx.coroutines.flow.MutableStateFlow
34-
import kotlinx.coroutines.runBlocking
3536
import kotlinx.coroutines.selects.select
3637
import kotlinx.coroutines.suspendCancellableCoroutine
38+
import kotlinx.coroutines.test.runTest
3739
import kotlinx.coroutines.withTimeout
3840
import kotlin.coroutines.CoroutineContext
3941
import kotlin.test.AfterTest
@@ -171,14 +173,14 @@ internal class WorkflowNodeTest {
171173
)
172174
node.render(workflow, "")("event")
173175

174-
val result = runBlocking {
175-
withTimeout(10) {
176+
runTest {
177+
val result = withTimeout(10) {
176178
select<WorkflowOutput<String>?> {
177179
node.tick(this)
178180
}
179181
}
182+
assertEquals("tick:event", result?.value)
180183
}
181-
assertEquals("tick:event", result?.value)
182184
}
183185

184186
@Test fun `accepts events sent to stale renderings`() {
@@ -208,16 +210,16 @@ internal class WorkflowNodeTest {
208210
sink("event")
209211
sink("event2")
210212

211-
val result = runBlocking {
212-
withTimeout(10) {
213+
runTest {
214+
val result = withTimeout(10) {
213215
List(2) {
214216
select<WorkflowOutput<String>?> {
215217
node.tick(this)
216218
}
217219
}
218220
}
221+
assertEquals(listOf("tick:event", "tick:event2"), result.map { it?.value })
219222
}
220-
assertEquals(listOf("tick:event", "tick:event2"), result.map { it?.value })
221223
}
222224

223225
@Test fun `send allows subsequent events on same rendering`() {
@@ -262,7 +264,7 @@ internal class WorkflowNodeTest {
262264
snapshot = null, baseContext = context
263265
)
264266

265-
runBlocking {
267+
runTest {
266268
node.render(workflow.asStatefulWorkflow(), Unit)
267269
assertTrue(started)
268270
}
@@ -300,16 +302,15 @@ internal class WorkflowNodeTest {
300302
)
301303
node.render(workflow.asStatefulWorkflow(), Unit)
302304

303-
val result = runBlocking {
305+
runTest {
304306
// Result should be available instantly, any delay at all indicates something is broken.
305-
withTimeout(1) {
307+
val result = withTimeout(1) {
306308
select<WorkflowOutput<String>?> {
307309
node.tick(this)
308310
}
309311
}
312+
assertEquals("result", result?.value)
310313
}
311-
312-
assertEquals("result", result?.value)
313314
}
314315

315316
@Test fun `sideEffect is cancelled when stops being ran`() {
@@ -329,7 +330,7 @@ internal class WorkflowNodeTest {
329330
snapshot = null, baseContext = context
330331
)
331332

332-
runBlocking {
333+
runTest {
333334
node.render(workflow.asStatefulWorkflow(), true)
334335
assertNull(cancellationException)
335336

@@ -355,7 +356,7 @@ internal class WorkflowNodeTest {
355356
snapshot = null, baseContext = context
356357
)
357358

358-
runBlocking {
359+
runTest {
359360
node.render(workflow.asStatefulWorkflow(), Unit)
360361
assertNull(cancellationException)
361362

@@ -381,7 +382,7 @@ internal class WorkflowNodeTest {
381382
snapshot = null, baseContext = context
382383
)
383384

384-
runBlocking {
385+
runTest {
385386
node.render(workflow.asStatefulWorkflow(), 0)
386387
assertFalse(cancelled)
387388
assertEquals(1, renderPasses)
@@ -406,7 +407,7 @@ internal class WorkflowNodeTest {
406407
snapshot = null, baseContext = context
407408
)
408409

409-
runBlocking {
410+
runTest {
410411
node.render(workflow.asStatefulWorkflow(), 0)
411412
assertEquals(listOf(0), seenProps)
412413
assertEquals(1, renderPasses)
@@ -1097,7 +1098,7 @@ internal class WorkflowNodeTest {
10971098

10981099
sink.send("hello")
10991100

1100-
runBlocking {
1101+
runTest {
11011102
select<WorkflowOutput<String>?> {
11021103
node.tick(this)
11031104
}
@@ -1123,13 +1124,12 @@ internal class WorkflowNodeTest {
11231124

11241125
rendering.send("hello")
11251126

1126-
val output = runBlocking {
1127-
select<WorkflowOutput<String>?> {
1127+
runTest {
1128+
val output = select<WorkflowOutput<String>?> {
11281129
node.tick(this)
11291130
}
1131+
assertEquals("output:hello", output?.value)
11301132
}
1131-
1132-
assertEquals("output:hello", output?.value)
11331133
}
11341134

11351135
@Test fun `actionSink action allows null output`() {
@@ -1148,13 +1148,12 @@ internal class WorkflowNodeTest {
11481148

11491149
rendering.send("hello")
11501150

1151-
val output = runBlocking {
1152-
select<WorkflowOutput<String>?> {
1151+
runTest {
1152+
val output = select<WorkflowOutput<String>?> {
11531153
node.tick(this)
11541154
}
1155+
assertNull(output?.value)
11551156
}
1156-
1157-
assertNull(output?.value)
11581157
}
11591158

11601159
@Test fun `child action changes state`() {
@@ -1176,7 +1175,7 @@ internal class WorkflowNodeTest {
11761175
)
11771176
node.render(workflow.asStatefulWorkflow(), Unit)
11781177

1179-
runBlocking {
1178+
runTest {
11801179
select<WorkflowOutput<String>?> {
11811180
node.tick(this)
11821181
}
@@ -1202,13 +1201,12 @@ internal class WorkflowNodeTest {
12021201
)
12031202
node.render(workflow.asStatefulWorkflow(), Unit)
12041203

1205-
val output = runBlocking {
1206-
select<WorkflowOutput<String>?> {
1204+
runTest {
1205+
val output = select<WorkflowOutput<String>?> {
12071206
node.tick(this)
12081207
}
1208+
assertEquals("output:child:hello", output?.value)
12091209
}
1210-
1211-
assertEquals("output:child:hello", output?.value)
12121210
}
12131211

12141212
@Test fun `child action allows null output`() {
@@ -1227,13 +1225,12 @@ internal class WorkflowNodeTest {
12271225
)
12281226
node.render(workflow.asStatefulWorkflow(), Unit)
12291227

1230-
val output = runBlocking {
1231-
select<WorkflowOutput<String>?> {
1228+
runTest {
1229+
val output = select<WorkflowOutput<String>?> {
12321230
node.tick(this)
12331231
}
1232+
assertNull(output?.value)
12341233
}
1235-
1236-
assertNull(output?.value)
12371234
}
12381235

12391236
private class TestSession(override val sessionId: Long = 0) : WorkflowSession {

workflow-rx2/dependencies/runtimeClasspath.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
77
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
88
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
99
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
10-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
11-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
12-
org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.5.1
13-
org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.5.1
10+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
11+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
12+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
13+
org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.6.1
14+
org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.6.1
1415
org.jetbrains:annotations:13.0
1516
org.reactivestreams:reactive-streams:1.0.3

workflow-testing/dependencies/runtimeClasspath.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
:workflow-runtime
44
com.squareup.okio:okio-jvm:3.0.0
55
com.squareup.okio:okio:3.0.0
6-
net.java.dev.jna:jna-platform:5.5.0
7-
net.java.dev.jna:jna:5.5.0
86
org.jetbrains.kotlin:kotlin-bom:1.6.10
97
org.jetbrains.kotlin:kotlin-reflect:1.6.10
108
org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10
119
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10
1210
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
1311
org.jetbrains.kotlin:kotlin-stdlib:1.6.10
14-
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.1
15-
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1
16-
org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.5.1
17-
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1
12+
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
13+
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
14+
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
15+
org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:1.6.1
16+
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1
1817
org.jetbrains:annotations:13.0

workflow-testing/src/test/java/com/squareup/workflow1/WorkerTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
package com.squareup.workflow1
44

55
import com.squareup.workflow1.testing.test
6+
import kotlinx.coroutines.ExperimentalCoroutinesApi
67
import kotlinx.coroutines.flow.flowOn
7-
import kotlinx.coroutines.test.TestCoroutineDispatcher
8+
import kotlinx.coroutines.test.StandardTestDispatcher
89
import kotlin.test.Test
910
import kotlin.test.assertEquals
1011
import kotlin.test.assertNotSame
1112
import kotlin.test.assertTrue
1213

1314
/** Worker tests that use the [Worker.test] function. Core tests are in the core module. */
15+
@OptIn(ExperimentalCoroutinesApi::class)
1416
internal class WorkerTest {
1517

1618
private class ExpectedException : RuntimeException()
@@ -119,7 +121,7 @@ internal class WorkerTest {
119121
}
120122

121123
@Test fun `timer emits and finishes after delay`() {
122-
val testDispatcher = TestCoroutineDispatcher()
124+
val testDispatcher = StandardTestDispatcher()
123125
val worker = Worker.timer(1000)
124126
// Run the timer on the test dispatcher so we can control time.
125127
.transform { it.flowOn(testDispatcher) }
@@ -128,11 +130,13 @@ internal class WorkerTest {
128130
assertNoOutput()
129131
assertNotFinished()
130132

131-
testDispatcher.advanceTimeBy(999)
133+
testDispatcher.scheduler.advanceTimeBy(999)
134+
testDispatcher.scheduler.runCurrent()
132135
assertNoOutput()
133136
assertNotFinished()
134137

135-
testDispatcher.advanceTimeBy(1)
138+
testDispatcher.scheduler.advanceTimeBy(1)
139+
testDispatcher.scheduler.runCurrent()
136140
assertEquals(Unit, nextOutput())
137141
assertFinished()
138142
}

workflow-testing/src/test/java/com/squareup/workflow1/testing/RenderIdempotencyCheckerTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import com.squareup.workflow1.stateless
88
import kotlinx.coroutines.CoroutineScope
99
import kotlinx.coroutines.Dispatchers.Unconfined
1010
import kotlinx.coroutines.ExperimentalCoroutinesApi
11-
import kotlinx.coroutines.Job
1211
import kotlinx.coroutines.flow.MutableStateFlow
13-
import kotlinx.coroutines.test.TestCoroutineScope
12+
import kotlinx.coroutines.test.TestScope
1413
import kotlin.test.Test
1514
import kotlin.test.assertEquals
1615

@@ -26,8 +25,7 @@ class RenderIdempotencyCheckerTest {
2625
rootRenders++
2726
renderChild(leafWorkflow)
2827
}
29-
val scope = TestCoroutineScope(Job())
30-
.apply { pauseDispatcher() }
28+
val scope = TestScope()
3129

3230
renderWorkflowIn(
3331
rootWorkflow, scope, MutableStateFlow(Unit), interceptors = listOf(RenderIdempotencyChecker)

0 commit comments

Comments
 (0)