@@ -3,6 +3,7 @@ package com.squareup.workflow1.internal
3
3
import com.squareup.workflow1.NoopWorkflowInterceptor
4
4
import com.squareup.workflow1.Worker
5
5
import com.squareup.workflow1.Workflow
6
+ import com.squareup.workflow1.WorkflowOutput
6
7
import com.squareup.workflow1.action
7
8
import com.squareup.workflow1.runningWorker
8
9
import com.squareup.workflow1.stateful
@@ -52,10 +53,11 @@ internal class WorkflowRunnerTest {
52
53
val props = MutableStateFlow (" initial" )
53
54
val runner = WorkflowRunner (workflow, props)
54
55
runner.nextRendering()
55
- val output = scope.async { runner.nextOutput() }
56
+
57
+ val outputDeferred = scope.async { runner.nextOutput() }
56
58
57
59
scope.runCurrent()
58
- assertTrue(output .isActive)
60
+ assertTrue(outputDeferred .isActive)
59
61
}
60
62
61
63
@Test fun `initial nextOutput() handles props changed after initialization` () {
@@ -100,10 +102,7 @@ internal class WorkflowRunnerTest {
100
102
val initialRendering = runner.nextRendering().rendering
101
103
assertEquals(" initial" , initialRendering)
102
104
103
- val output = with (scope.async { runner.nextOutput() }) {
104
- scope.advanceUntilIdle()
105
- getCompleted()
106
- }
105
+ val output = runner.runTillNextOutput()
107
106
assertEquals(" output: work" , output?.value)
108
107
109
108
val updatedRendering = runner.nextRendering().rendering
@@ -131,19 +130,13 @@ internal class WorkflowRunnerTest {
131
130
132
131
// The order in which props update and workflow update are processed is deterministic, based
133
132
// on the order they appear in the select block in nextOutput.
134
- val firstOutput = with (scope.async { runner.nextOutput() }) {
135
- scope.advanceUntilIdle()
136
- getCompleted()
137
- }
133
+ val firstOutput = runner.runTillNextOutput()
138
134
// First update will be props, so no output value.
139
135
assertNull(firstOutput)
140
136
val secondRendering = runner.nextRendering().rendering
141
137
assertEquals(" changed props|initial state(initial props)" , secondRendering)
142
138
143
- val secondOutput = with (scope.async { runner.nextOutput() }) {
144
- scope.advanceUntilIdle()
145
- getCompleted()
146
- }
139
+ val secondOutput = runner.runTillNextOutput()
147
140
assertEquals(" output: work" , secondOutput?.value)
148
141
val thirdRendering = runner.nextRendering().rendering
149
142
assertEquals(" changed props|state: work" , thirdRendering)
@@ -227,6 +220,13 @@ internal class WorkflowRunnerTest {
227
220
assertEquals(" foo" , cancellationException!! .message)
228
221
}
229
222
223
+
224
+ private fun <T > WorkflowRunner <* , T , * >.runTillNextOutput (): WorkflowOutput <T >? = scope.run {
225
+ val firstOutputDeferred = async { nextOutput() }
226
+ runCurrent()
227
+ firstOutputDeferred.getCompleted()
228
+ }
229
+
230
230
@Suppress(" TestFunctionName" )
231
231
private fun <P , O : Any , R > WorkflowRunner (
232
232
workflow : Workflow <P , O , R >,
0 commit comments