Skip to content

Commit 358b9bd

Browse files
Merge pull request #996 from square/OG/issue-994
Mark runningWorker with no output as @deprecated
2 parents e1e00ac + 7358064 commit 358b9bd

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ public fun <PropsT, StateT, OutputT, ChildRenderingT>
249249
* Ensures a [Worker] that never emits anything is running. Since [worker] can't emit anything,
250250
* it can't trigger any [WorkflowAction]s.
251251
*
252-
* If your [Worker] does not output anything, then simply use [runningSideEffect].
252+
* If your [Worker] does not output anything, then simply use [BaseRenderContext.runningSideEffect].
253253
*
254254
* @param key An optional string key that is used to distinguish between identical [Worker]s.
255255
*/
256+
@Deprecated(
257+
message = "Use [BaseRenderContext.runningSideEffect] instead.",
258+
replaceWith = ReplaceWith(expression = "runningSideEffect(key) { ... }", "")
259+
)
256260
public inline fun <reified W : Worker<Nothing>, PropsT, StateT, OutputT>
257261
BaseRenderContext<PropsT, StateT, OutputT>.runningWorker(
258262
worker: W,

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ internal class WorkerCompositionIntegrationTest {
5151
}
5252
}
5353
val workflow = Workflow.stateless<Boolean, Nothing, Unit> { props ->
54+
// Suppress runningWorker usage because we want to make sure this
55+
// test still properly tests usage with LifecycleWorker
56+
@Suppress("DEPRECATION")
5457
if (props) runningWorker(worker)
5558
}
5659

@@ -73,7 +76,12 @@ internal class WorkerCompositionIntegrationTest {
7376
stops++
7477
}
7578
}
76-
val workflow = Workflow.stateless<Unit, Nothing, Unit> { runningWorker(worker) }
79+
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
80+
// Suppress runningWorker usage because we want to make sure this
81+
// test still properly tests usage with LifecycleWorker
82+
@Suppress("DEPRECATION")
83+
runningWorker(worker)
84+
}
7785

7886
workflow.launchForTestingFromStartWith {
7987
assertEquals(1, starts)
@@ -102,6 +110,9 @@ internal class WorkerCompositionIntegrationTest {
102110
}
103111
}
104112
val workflow = Workflow.stateless<Boolean, Nothing, Unit> { props ->
113+
// Suppress runningWorker usage because we want to make sure this
114+
// test still properly tests usage with LifecycleWorker
115+
@Suppress("DEPRECATION")
105116
if (props) runningWorker(worker)
106117
}
107118

@@ -212,6 +223,9 @@ internal class WorkerCompositionIntegrationTest {
212223
@Suppress("UNCHECKED_CAST")
213224
val worker = Worker.from { Unit } as Worker<Nothing>
214225
val workflow = Workflow.stateless<Unit, Unit, Unit> {
226+
// Suppress runningWorker usage because we want to make sure the deprecated
227+
// method still throws an exception as expected
228+
@Suppress("DEPRECATION")
215229
runningWorker(worker)
216230
}
217231

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ internal class RealRenderTesterTest {
543543
}
544544

545545
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
546+
// Suppress runningWorker usage because we want to make sure the internal exception
547+
// is not thrown when we don't expect an output
548+
@Suppress("DEPRECATION")
546549
runningWorker(worker)
547550
}
548551
val tester = workflow.testRender(Unit)
@@ -584,6 +587,9 @@ internal class RealRenderTesterTest {
584587
val worker = MySpecialWorker()
585588

586589
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
590+
// Suppress runningWorker usage because we are testing/validating the internal
591+
// exception that is thrown
592+
@Suppress("DEPRECATION")
587593
runningWorker(worker)
588594
}
589595
val tester = workflow.testRender(Unit).requireExplicitWorkerExpectations()
@@ -626,6 +632,9 @@ internal class RealRenderTesterTest {
626632
}
627633

628634
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
635+
// Suppress runningWorker usage because we want to make sure the internal exception
636+
// is not thrown when we don't expect an output, even with a unique key specified
637+
@Suppress("DEPRECATION")
629638
runningWorker(worker, key = "key")
630639
}
631640
val tester = workflow.testRender(Unit)
@@ -641,6 +650,9 @@ internal class RealRenderTesterTest {
641650
}
642651

643652
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
653+
// Suppress runningWorker usage because we are
654+
// testing/validating the internal exception that is thrown
655+
@Suppress("DEPRECATION")
644656
runningWorker(worker, key = "key")
645657
}
646658
val tester = workflow.testRender(Unit)
@@ -662,6 +674,9 @@ internal class RealRenderTesterTest {
662674
}
663675

664676
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
677+
// Suppress runningWorker usage because we are
678+
// expecting an exception to be thrown with mismatched keys
679+
@Suppress("DEPRECATION")
665680
runningWorker(worker, key = "key")
666681
}
667682
val tester = workflow.testRender(Unit)
@@ -687,6 +702,7 @@ internal class RealRenderTesterTest {
687702

688703
val worker = EmptyWorker()
689704
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
705+
@Suppress("DEPRECATION")
690706
runningWorker(worker)
691707
}
692708
val tester = workflow.testRender(Unit)
@@ -711,6 +727,9 @@ internal class RealRenderTesterTest {
711727
val stringWorker: Worker<String> = emptyFlow<String>().asWorker()
712728

713729
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
730+
// Suppress usage as we are testing a comparisons of unique workers
731+
// even though they have the same key.
732+
@Suppress("DEPRECATION")
714733
runningWorker(lifecycleWorker)
715734
runningWorker(stringWorker) { noAction() }
716735
}
@@ -722,7 +741,11 @@ internal class RealRenderTesterTest {
722741
// No exception, no bug.
723742
}
724743

725-
@Test fun `runningWorker distinguishes between specific Nothing workers`() {
744+
// Suppress runningWorker in this test as we are testing the
745+
// uniqueness of workers using similar objects as keys
746+
@Suppress("DEPRECATION")
747+
@Test
748+
fun `runningWorker distinguishes between specific Nothing workers`() {
726749
val workerA = object : LifecycleWorker() {}
727750
val workerB = object : LifecycleWorker() {}
728751

0 commit comments

Comments
 (0)