Skip to content

Commit 4b493ba

Browse files
committed
Bump coroutines to 1.6.1
1 parent a94bc30 commit 4b493ba

File tree

11 files changed

+230
-271
lines changed

11 files changed

+230
-271
lines changed

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ kotest = "5.1.0"
4747
kotlin = "1.6.10"
4848

4949
kotlinx-binary-compatibility = "0.6.0"
50-
kotlinx-coroutines = "1.5.1"
50+
kotlinx-coroutines = "1.6.1"
5151
kotlinx-serialization-json = "1.3.2"
5252
kotlinx-benchmark = "0.4.2"
5353

workflow-core/src/jvmTest/kotlin/com/squareup/workflow1/SinkTest.kt

+54-54
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import kotlinx.coroutines.channels.Channel
66
import kotlinx.coroutines.flow.MutableStateFlow
77
import kotlinx.coroutines.flow.consumeAsFlow
88
import kotlinx.coroutines.launch
9-
import kotlinx.coroutines.test.runBlockingTest
9+
import kotlinx.coroutines.test.StandardTestDispatcher
10+
import kotlinx.coroutines.test.UnconfinedTestDispatcher
11+
import kotlinx.coroutines.test.advanceUntilIdle
12+
import kotlinx.coroutines.test.runTest
13+
import kotlinx.coroutines.withContext
1014
import java.util.concurrent.atomic.AtomicInteger
1115
import kotlin.test.Test
1216
import kotlin.test.assertEquals
@@ -23,40 +27,38 @@ internal class SinkTest {
2327

2428
private val sink = RecordingSink()
2529

26-
@Test fun `collectToSink sends action`() {
27-
runBlockingTest {
28-
val flow = MutableStateFlow(1)
29-
val collector = launch {
30-
flow.collectToSink(sink) {
31-
action {
32-
state = "$props $state $it"
33-
setOutput("output: $it")
34-
}
30+
@Test fun `collectToSink sends action`() = runTest {
31+
val flow = MutableStateFlow(1)
32+
val collector = launch {
33+
flow.collectToSink(sink) {
34+
action {
35+
state = "$props $state $it"
36+
setOutput("output: $it")
3537
}
3638
}
39+
}
3740

38-
advanceUntilIdle()
39-
assertEquals(1, sink.actions.size)
40-
sink.actions.removeFirst()
41-
.let { action ->
42-
val (newState, output) = action.applyTo("props", "state")
43-
assertEquals("props state 1", newState)
44-
assertEquals("output: 1", output?.value)
45-
}
46-
assertTrue(sink.actions.isEmpty())
47-
48-
flow.value = 2
49-
advanceUntilIdle()
50-
assertEquals(1, sink.actions.size)
51-
sink.actions.removeFirst()
52-
.let { action ->
53-
val (newState, output) = action.applyTo("props", "state")
54-
assertEquals("props state 2", newState)
55-
assertEquals("output: 2", output?.value)
56-
}
41+
advanceUntilIdle()
42+
assertEquals(1, sink.actions.size)
43+
sink.actions.removeFirst()
44+
.let { action ->
45+
val (newState, output) = action.applyTo("props", "state")
46+
assertEquals("props state 1", newState)
47+
assertEquals("output: 1", output?.value)
48+
}
49+
assertTrue(sink.actions.isEmpty())
50+
51+
flow.value = 2
52+
advanceUntilIdle()
53+
assertEquals(1, sink.actions.size)
54+
sink.actions.removeFirst()
55+
.let { action ->
56+
val (newState, output) = action.applyTo("props", "state")
57+
assertEquals("props state 2", newState)
58+
assertEquals("output: 2", output?.value)
59+
}
5760

58-
collector.cancel()
59-
}
61+
collector.cancel()
6062
}
6163

6264
@Test fun `collectToSink propagates backpressure`() {
@@ -69,7 +71,7 @@ internal class SinkTest {
6971
sentActions += it
7072
}
7173

72-
runBlockingTest {
74+
runTest(UnconfinedTestDispatcher()) {
7375
val collectJob = launch {
7476
flow.collectToSink(sink) { action { setOutput(it) } }
7577
}
@@ -118,7 +120,7 @@ internal class SinkTest {
118120
setOutput("output")
119121
}
120122

121-
runBlockingTest {
123+
runTest {
122124
launch { sink.sendAndAwaitApplication(action) }
123125
advanceUntilIdle()
124126

@@ -130,33 +132,32 @@ internal class SinkTest {
130132
}
131133
}
132134

133-
@Test fun `sendAndAwaitApplication suspends until after applied`() {
134-
runBlockingTest {
135-
var resumed = false
136-
val action = action<String, String, String> {
137-
assertFalse(resumed)
138-
}
139-
launch {
140-
sink.sendAndAwaitApplication(action)
141-
resumed = true
142-
}
143-
advanceUntilIdle()
135+
@Test fun `sendAndAwaitApplication suspends until after applied`() = runTest {
136+
var resumed = false
137+
val action = action<String, String, String> {
144138
assertFalse(resumed)
145-
assertEquals(1, sink.actions.size)
139+
}
140+
launch {
141+
sink.sendAndAwaitApplication(action)
142+
resumed = true
143+
}
144+
advanceUntilIdle()
145+
assertFalse(resumed)
146+
assertEquals(1, sink.actions.size)
146147

147-
val enqueuedAction = sink.actions.removeFirst()
148-
pauseDispatcher()
149-
enqueuedAction.applyTo("props", "state")
148+
val enqueuedAction = sink.actions.removeFirst()
150149

150+
withContext(StandardTestDispatcher(testScheduler)) {
151+
enqueuedAction.applyTo("props", "state")
151152
assertFalse(resumed)
152-
resumeDispatcher()
153-
advanceUntilIdle()
154-
assertTrue(resumed)
155153
}
154+
155+
advanceUntilIdle()
156+
assertTrue(resumed)
156157
}
157158

158-
@Test fun `sendAndAwaitApplication doesn't apply action when cancelled while suspended`() {
159-
runBlockingTest {
159+
@Test fun `sendAndAwaitApplication doesn't apply action when cancelled while suspended`() =
160+
runTest {
160161
var applied = false
161162
val action = action<String, String, String> {
162163
applied = true
@@ -176,7 +177,6 @@ internal class SinkTest {
176177
assertEquals("state", newState)
177178
assertNull(output)
178179
}
179-
}
180180

181181
private class RecordingSink : Sink<WorkflowAction<String, String, String>> {
182182
val actions = mutableListOf<WorkflowAction<String, String, String>>()

workflow-runtime/src/jvmMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class RealRenderContext<out PropsT, StateT, OutputT>(
4848
"Expected sink to not be sent to until after the render pass. Received action: $value"
4949
)
5050
}
51-
eventActionsChannel.offer(value)
51+
eventActionsChannel.trySend(value)
5252
}
5353

5454
override fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(

0 commit comments

Comments
 (0)