From eff6703896b46eebb04346117f1d27043c6ea2da Mon Sep 17 00:00:00 2001 From: crocsandcoffee Date: Tue, 2 May 2023 02:41:08 -0700 Subject: [PATCH 1/3] Mark runningWorker with no output as @Deprecated --- .../kotlin/com/squareup/workflow1/BaseRenderContext.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt index 83c201207..e28dabdad 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt @@ -249,10 +249,14 @@ public fun * Ensures a [Worker] that never emits anything is running. Since [worker] can't emit anything, * it can't trigger any [WorkflowAction]s. * - * If your [Worker] does not output anything, then simply use [runningSideEffect]. + * If your [Worker] does not output anything, then simply use [BaseRenderContext.runningSideEffect]. * * @param key An optional string key that is used to distinguish between identical [Worker]s. */ +@Deprecated( + message = "Use [BaseRenderContext.runningSideEffect] instead.", + replaceWith = ReplaceWith(expression = "runningSideEffect(key) { ... }", "") +) public inline fun , PropsT, StateT, OutputT> BaseRenderContext.runningWorker( worker: W, From a3e3e287637f8d723f0f5e528d1fa729b07a7b11 Mon Sep 17 00:00:00 2001 From: crocsandcoffee Date: Thu, 6 Jul 2023 00:39:00 -0400 Subject: [PATCH 2/3] suppress warnings in tests --- .../WorkerCompositionIntegrationTest.kt | 16 +++++++++++++- .../workflow1/testing/RealRenderTesterTest.kt | 22 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/WorkerCompositionIntegrationTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/WorkerCompositionIntegrationTest.kt index 2f5c4f7db..cf524f923 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/WorkerCompositionIntegrationTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/WorkerCompositionIntegrationTest.kt @@ -51,6 +51,9 @@ internal class WorkerCompositionIntegrationTest { } } val workflow = Workflow.stateless { props -> + // Suppress runningWorker usage because we want to make sure this + // test still properly tests usage with LifecycleWorker + @Suppress("DEPRECATION") if (props) runningWorker(worker) } @@ -73,7 +76,12 @@ internal class WorkerCompositionIntegrationTest { stops++ } } - val workflow = Workflow.stateless { runningWorker(worker) } + val workflow = Workflow.stateless { + // Suppress runningWorker usage because we want to make sure this + // test still properly tests usage with LifecycleWorker + @Suppress("DEPRECATION") + runningWorker(worker) + } workflow.launchForTestingFromStartWith { assertEquals(1, starts) @@ -102,6 +110,9 @@ internal class WorkerCompositionIntegrationTest { } } val workflow = Workflow.stateless { props -> + // Suppress runningWorker usage because we want to make sure this + // test still properly tests usage with LifecycleWorker + @Suppress("DEPRECATION") if (props) runningWorker(worker) } @@ -212,6 +223,9 @@ internal class WorkerCompositionIntegrationTest { @Suppress("UNCHECKED_CAST") val worker = Worker.from { Unit } as Worker val workflow = Workflow.stateless { + // Suppress runningWorker usage because we want to make sure the deprecated + // method still throws an exception as expected + @Suppress("DEPRECATION") runningWorker(worker) } diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt index 445af5d22..093ae6950 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt @@ -543,6 +543,9 @@ internal class RealRenderTesterTest { } val workflow = Workflow.stateless { + // Suppress runningWorker usage because we want to make sure the internal exception + // is not thrown when we don't expect an output + @Suppress("DEPRECATION") runningWorker(worker) } val tester = workflow.testRender(Unit) @@ -584,6 +587,9 @@ internal class RealRenderTesterTest { val worker = MySpecialWorker() val workflow = Workflow.stateless { + // Suppress runningWorker usage because we are testing/validating the internal + // exception that is thrown + @Suppress("DEPRECATION") runningWorker(worker) } val tester = workflow.testRender(Unit).requireExplicitWorkerExpectations() @@ -626,6 +632,9 @@ internal class RealRenderTesterTest { } val workflow = Workflow.stateless { + // Suppress runningWorker usage because we want to make sure the internal exception + // is not thrown when we don't expect an output, even with a unique key specified + @Suppress("DEPRECATION") runningWorker(worker, key = "key") } val tester = workflow.testRender(Unit) @@ -641,6 +650,9 @@ internal class RealRenderTesterTest { } val workflow = Workflow.stateless { + // Suppress runningWorker usage because we are + // testing/validating the internal exception that is thrown + @Suppress("DEPRECATION") runningWorker(worker, key = "key") } val tester = workflow.testRender(Unit) @@ -662,6 +674,9 @@ internal class RealRenderTesterTest { } val workflow = Workflow.stateless { + // Suppress runningWorker usage because we are + // expecting an exception to be thrown with mismatched keys + @Suppress("DEPRECATION") runningWorker(worker, key = "key") } val tester = workflow.testRender(Unit) @@ -687,6 +702,7 @@ internal class RealRenderTesterTest { val worker = EmptyWorker() val workflow = Workflow.stateless { + @Suppress("DEPRECATION") runningWorker(worker) } val tester = workflow.testRender(Unit) @@ -711,6 +727,9 @@ internal class RealRenderTesterTest { val stringWorker: Worker = emptyFlow().asWorker() val workflow = Workflow.stateless { + // Suppress usage as we are testing a comparisons of unique workers + // even though they have the same key. + @Suppress("DEPRECATION") runningWorker(lifecycleWorker) runningWorker(stringWorker) { noAction() } } @@ -722,6 +741,9 @@ internal class RealRenderTesterTest { // No exception, no bug. } + // Suppress runningWorker in this test as we are testing the + // uniqueness of workers using similar objects as keys + @Suppress("DEPRECATION") @Test fun `runningWorker distinguishes between specific Nothing workers`() { val workerA = object : LifecycleWorker() {} val workerB = object : LifecycleWorker() {} From 7358064d5264595dc3a75a538d9d2ee5dfee47f5 Mon Sep 17 00:00:00 2001 From: crocsandcoffee Date: Thu, 6 Jul 2023 04:43:29 +0000 Subject: [PATCH 3/3] Apply changes from ktLintFormat Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../com/squareup/workflow1/testing/RealRenderTesterTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt index 093ae6950..0b4c2e10c 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt @@ -744,7 +744,8 @@ internal class RealRenderTesterTest { // Suppress runningWorker in this test as we are testing the // uniqueness of workers using similar objects as keys @Suppress("DEPRECATION") - @Test fun `runningWorker distinguishes between specific Nothing workers`() { + @Test + fun `runningWorker distinguishes between specific Nothing workers`() { val workerA = object : LifecycleWorker() {} val workerB = object : LifecycleWorker() {}