Skip to content

Commit 98d00ab

Browse files
Merge pull request #1499 from square/codex/renderfortest-teardown
🤖 [codex] Add renderForTest teardown policy
2 parents a2010d7 + 1f90e57 commit 98d00ab

4 files changed

Lines changed: 260 additions & 73 deletions

File tree

workflow-testing/api/workflow-testing.api

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ public final class com/squareup/workflow1/testing/WorkerTesterKt {
137137
public static synthetic fun test$default (Lcom/squareup/workflow1/Worker;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
138138
}
139139

140+
public abstract interface class com/squareup/workflow1/testing/WorkflowRuntimeTeardown {
141+
}
142+
143+
public final class com/squareup/workflow1/testing/WorkflowRuntimeTeardown$Cancel : com/squareup/workflow1/testing/WorkflowRuntimeTeardown {
144+
public static final field INSTANCE Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown$Cancel;
145+
public fun equals (Ljava/lang/Object;)Z
146+
public fun hashCode ()I
147+
public fun toString ()Ljava/lang/String;
148+
}
149+
150+
public final class com/squareup/workflow1/testing/WorkflowRuntimeTeardown$CancelAndAwait : com/squareup/workflow1/testing/WorkflowRuntimeTeardown {
151+
public synthetic fun <init> (JZILkotlin/jvm/internal/DefaultConstructorMarker;)V
152+
public synthetic fun <init> (JZLkotlin/jvm/internal/DefaultConstructorMarker;)V
153+
public final fun component1-UwyO8pc ()J
154+
public final fun component2 ()Z
155+
public final fun copy-VtjQ1oo (JZ)Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown$CancelAndAwait;
156+
public static synthetic fun copy-VtjQ1oo$default (Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown$CancelAndAwait;JZILjava/lang/Object;)Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown$CancelAndAwait;
157+
public fun equals (Ljava/lang/Object;)Z
158+
public final fun getDrainSchedulerAfterCancel ()Z
159+
public final fun getTimeout-UwyO8pc ()J
160+
public fun hashCode ()I
161+
public fun toString ()Ljava/lang/String;
162+
}
163+
140164
public final class com/squareup/workflow1/testing/WorkflowTestParams {
141165
public fun <init> ()V
142166
public fun <init> (Lcom/squareup/workflow1/testing/WorkflowTestParams$StartMode;ZLjava/util/Set;Lcom/squareup/workflow1/testing/DeprecatedLaunchSchedulerMode;)V
@@ -238,17 +262,17 @@ public final class com/squareup/workflow1/testing/WorkflowTurbine$Companion {
238262
}
239263

240264
public final class com/squareup/workflow1/testing/WorkflowTurbineKt {
241-
public static final fun renderForTest (Lcom/squareup/workflow1/StatefulWorkflow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
242-
public static final fun renderForTest (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
243-
public static synthetic fun renderForTest$default (Lcom/squareup/workflow1/StatefulWorkflow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
244-
public static synthetic fun renderForTest$default (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
245-
public static final fun renderForTestForStartWith (Lcom/squareup/workflow1/Workflow;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowTestParams;Ljava/util/List;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
246-
public static final fun renderForTestForStartWith (Lcom/squareup/workflow1/Workflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Ljava/util/List;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
247-
public static synthetic fun renderForTestForStartWith$default (Lcom/squareup/workflow1/Workflow;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowTestParams;Ljava/util/List;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
248-
public static synthetic fun renderForTestForStartWith$default (Lcom/squareup/workflow1/Workflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Ljava/util/List;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
249-
public static final fun renderForTestFromStateWith (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
250-
public static final fun renderForTestFromStateWith (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
251-
public static synthetic fun renderForTestFromStateWith$default (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
252-
public static synthetic fun renderForTestFromStateWith$default (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
265+
public static final fun renderForTest (Lcom/squareup/workflow1/StatefulWorkflow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
266+
public static final fun renderForTest (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
267+
public static synthetic fun renderForTest$default (Lcom/squareup/workflow1/StatefulWorkflow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
268+
public static synthetic fun renderForTest$default (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
269+
public static final fun renderForTestForStartWith (Lcom/squareup/workflow1/Workflow;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowTestParams;Ljava/util/List;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
270+
public static final fun renderForTestForStartWith (Lcom/squareup/workflow1/Workflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Ljava/util/List;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
271+
public static synthetic fun renderForTestForStartWith$default (Lcom/squareup/workflow1/Workflow;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowTestParams;Ljava/util/List;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
272+
public static synthetic fun renderForTestForStartWith$default (Lcom/squareup/workflow1/Workflow;Lkotlinx/coroutines/flow/StateFlow;Lcom/squareup/workflow1/testing/WorkflowTestParams;Lkotlin/coroutines/CoroutineContext;Ljava/util/List;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
273+
public static final fun renderForTestFromStateWith (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
274+
public static final fun renderForTestFromStateWith (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;)V
275+
public static synthetic fun renderForTestFromStateWith$default (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
276+
public static synthetic fun renderForTestFromStateWith$default (Lcom/squareup/workflow1/StatefulWorkflow;Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/coroutines/CoroutineContext;Lcom/squareup/workflow1/testing/WorkflowRuntimeTeardown;Lkotlin/jvm/functions/Function2;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
253277
}
254278

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.squareup.workflow1.testing
2+
3+
import kotlin.time.Duration
4+
import kotlin.time.Duration.Companion.seconds
5+
6+
/**
7+
* Controls how `renderForTest` tears down the workflow runtime after the test block completes.
8+
*/
9+
public sealed interface WorkflowRuntimeTeardown {
10+
/**
11+
* Cancel the workflow runtime and return without waiting for cancellation cleanup to complete.
12+
*/
13+
public data object Cancel : WorkflowRuntimeTeardown
14+
15+
/**
16+
* Cancel the workflow runtime and wait for cancellation cleanup to complete.
17+
*
18+
* @param timeout The maximum time to wait for the runtime job to complete after cancellation.
19+
* @param drainSchedulerAfterCancel Whether to drain the test scheduler after cancelling the
20+
* runtime, and again after the runtime job completes.
21+
*/
22+
public data class CancelAndAwait(
23+
public val timeout: Duration = 1.seconds,
24+
public val drainSchedulerAfterCancel: Boolean = true,
25+
) : WorkflowRuntimeTeardown
26+
}

0 commit comments

Comments
 (0)