Skip to content

Commit 5f2ac61

Browse files
authored
Factored out Signal Tests (#383)
* Factored out Signal Tests * Shutdown takes about 6s after a few tests and it counts towards the global 10s timeout for tests. At least for in-memory tests we can call shutdownNow() instead and save time.
1 parent 9c384fc commit 5f2ac61

34 files changed

+1316
-972
lines changed

temporal-sdk/src/test/java/io/temporal/workflow/ActivityRetryWithMaxAttemptsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public class ActivityRetryWithMaxAttemptsTest {
4242

4343
@Rule
4444
public SDKTestWorkflowRule testWorkflowRule =
45-
SDKTestWorkflowRule.newBuilder()
46-
.setWorkflowTypes(TestActivityRetryWithMaxAttempts.class)
47-
.setWorkerInterceptors(
48-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
49-
.setActivityImplementations(activitiesImpl)
50-
.build();
45+
SDKTestWorkflowRule.newBuilder()
46+
.setWorkflowTypes(TestActivityRetryWithMaxAttempts.class)
47+
.setWorkerInterceptors(
48+
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
49+
.setActivityImplementations(activitiesImpl)
50+
.build();
5151

5252
@Test
5353
public void testActivityRetryWithMaxAttempts() {

temporal-sdk/src/test/java/io/temporal/workflow/AsyncActivityRetry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public class AsyncActivityRetry {
4242

4343
@Rule
4444
public SDKTestWorkflowRule testWorkflowRule =
45-
SDKTestWorkflowRule.newBuilder()
46-
.setWorkflowTypes(TestAsyncActivityRetry.class)
47-
.setActivityImplementations(activitiesImpl)
48-
.build();
45+
SDKTestWorkflowRule.newBuilder()
46+
.setWorkflowTypes(TestAsyncActivityRetry.class)
47+
.setActivityImplementations(activitiesImpl)
48+
.build();
4949

5050
@Test
5151
public void testAsyncActivityRetry() {

temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncLambdaWorkflowTest.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import static org.junit.Assert.assertNotNull;
2424

2525
import io.temporal.api.common.v1.WorkflowExecution;
26-
import io.temporal.client.WorkflowOptions;
27-
import io.temporal.testing.TestWorkflowRule;
28-
import io.temporal.testing.TracingWorkerInterceptor;
26+
import io.temporal.workflow.shared.SDKTestWorkflowRule;
2927
import io.temporal.workflow.shared.TestActivities;
3028
import io.temporal.workflow.shared.TestWorkflows;
3129
import java.time.Duration;
@@ -39,12 +37,10 @@ public class ChildAsyncLambdaWorkflowTest {
3937
new TestActivities.TestActivitiesImpl(null);
4038

4139
@Rule
42-
public TestWorkflowRule testWorkflowRule =
43-
TestWorkflowRule.newBuilder()
40+
public SDKTestWorkflowRule testWorkflowRule =
41+
SDKTestWorkflowRule.newBuilder()
4442
.setWorkflowTypes(TestWaitOnSignalWorkflowImpl.class, TestChildAsyncLambdaWorkflow.class)
4543
.setActivityImplementations(activitiesImpl)
46-
.setWorkerInterceptors(
47-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
4844
.build();
4945

5046
/**
@@ -55,18 +51,12 @@ public class ChildAsyncLambdaWorkflowTest {
5551
*/
5652
@Test
5753
public void testChildAsyncLambdaWorkflow() {
58-
WorkflowOptions.Builder options = WorkflowOptions.newBuilder();
59-
options.setWorkflowRunTimeout(Duration.ofSeconds(200));
60-
options.setWorkflowTaskTimeout(Duration.ofSeconds(60));
61-
options.setTaskQueue(testWorkflowRule.getTaskQueue());
6254
TestWorkflows.TestWorkflow1 client =
63-
testWorkflowRule
64-
.getWorkflowClient()
65-
.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options.build());
55+
testWorkflowRule.newWorkflowStub200sTimeoutOptions(TestWorkflows.TestWorkflow1.class);
6656
Assert.assertEquals(null, client.execute(testWorkflowRule.getTaskQueue()));
6757
}
6858

69-
public static class TestWaitOnSignalWorkflowImpl implements WorkflowTest.WaitOnSignalWorkflow {
59+
public static class TestWaitOnSignalWorkflowImpl implements WaitOnSignalWorkflow {
7060

7161
private final CompletablePromise<String> signal = Workflow.newPromise();
7262

@@ -93,8 +83,8 @@ public String execute(String taskQueue) {
9383
.setTaskQueue(taskQueue)
9484
.build();
9585

96-
WorkflowTest.WaitOnSignalWorkflow child =
97-
Workflow.newChildWorkflowStub(WorkflowTest.WaitOnSignalWorkflow.class, workflowOptions);
86+
WaitOnSignalWorkflow child =
87+
Workflow.newChildWorkflowStub(WaitOnSignalWorkflow.class, workflowOptions);
9888
Promise<Void> promise = Async.procedure(child::execute);
9989
Promise<WorkflowExecution> executionPromise = Workflow.getWorkflowExecution(child);
10090
assertNotNull(executionPromise);
@@ -107,4 +97,16 @@ public String execute(String taskQueue) {
10797
return null;
10898
}
10999
}
100+
101+
// This workflow is designed specifically for testing some internal logic in Async.procedure
102+
// and ChildWorkflowStubImpl. See comments on testChildAsyncLambdaWorkflow for more details.
103+
@WorkflowInterface
104+
public interface WaitOnSignalWorkflow {
105+
106+
@WorkflowMethod()
107+
void execute();
108+
109+
@SignalMethod
110+
void signal(String value);
111+
}
110112
}

temporal-sdk/src/test/java/io/temporal/workflow/ChildAsyncWorkflowTest.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121

2222
import static org.junit.Assert.assertEquals;
2323

24-
import io.temporal.client.WorkflowOptions;
25-
import io.temporal.testing.TestWorkflowRule;
26-
import io.temporal.testing.TracingWorkerInterceptor;
24+
import io.temporal.workflow.shared.SDKTestWorkflowRule;
2725
import io.temporal.workflow.shared.TestActivities;
2826
import io.temporal.workflow.shared.TestMultiargdsWorkflowFunctions;
2927
import io.temporal.workflow.shared.TestWorkflows;
30-
import java.time.Duration;
3128
import org.junit.Assert;
3229
import org.junit.Rule;
3330
import org.junit.Test;
@@ -38,26 +35,18 @@ public class ChildAsyncWorkflowTest {
3835
new TestActivities.TestActivitiesImpl(null);
3936

4037
@Rule
41-
public TestWorkflowRule testWorkflowRule =
42-
TestWorkflowRule.newBuilder()
38+
public SDKTestWorkflowRule testWorkflowRule =
39+
SDKTestWorkflowRule.newBuilder()
4340
.setWorkflowTypes(
4441
TestChildAsyncWorkflow.class,
4542
TestMultiargdsWorkflowFunctions.TestMultiargsWorkflowsImpl.class)
4643
.setActivityImplementations(activitiesImpl)
47-
.setWorkerInterceptors(
48-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
4944
.build();
5045

5146
@Test
5247
public void testChildAsyncWorkflow() {
53-
WorkflowOptions.Builder options = WorkflowOptions.newBuilder();
54-
options.setWorkflowRunTimeout(Duration.ofSeconds(200));
55-
options.setWorkflowTaskTimeout(Duration.ofSeconds(60));
56-
options.setTaskQueue(testWorkflowRule.getTaskQueue());
5748
TestWorkflows.TestWorkflow1 client =
58-
testWorkflowRule
59-
.getWorkflowClient()
60-
.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options.build());
49+
testWorkflowRule.newWorkflowStub200sTimeoutOptions(TestWorkflows.TestWorkflow1.class);
6150
Assert.assertEquals(null, client.execute(testWorkflowRule.getTaskQueue()));
6251
}
6352

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowAsyncRetryTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import io.temporal.common.RetryOptions;
2727
import io.temporal.failure.ApplicationFailure;
2828
import io.temporal.failure.ChildWorkflowFailure;
29-
import io.temporal.testing.TracingWorkerInterceptor;
3029
import io.temporal.testing.WorkflowReplayer;
3130
import io.temporal.workflow.shared.SDKTestWorkflowRule;
31+
import io.temporal.workflow.shared.TestActivities;
3232
import io.temporal.workflow.shared.TestWorkflows;
3333
import java.time.Duration;
3434
import org.junit.Assume;
@@ -37,17 +37,15 @@
3737

3838
public class ChildWorkflowAsyncRetryTest {
3939

40-
private final WorkflowTest.AngryChildActivityImpl angryChildActivity =
41-
new WorkflowTest.AngryChildActivityImpl();
40+
private final TestActivities.AngryChildActivityImpl angryChildActivity =
41+
new TestActivities.AngryChildActivityImpl();
4242

4343
@Rule
4444
public SDKTestWorkflowRule testWorkflowRule =
4545
SDKTestWorkflowRule.newBuilder()
4646
.setWorkflowTypes(
4747
TestChildWorkflowAsyncRetryWorkflow.class, WorkflowTest.AngryChild.class)
4848
.setActivityImplementations(angryChildActivity)
49-
.setWorkerInterceptors(
50-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
5149
.build();
5250

5351
@Test

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowCancellationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.temporal.client.WorkflowFailedException;
2828
import io.temporal.client.WorkflowStub;
2929
import io.temporal.failure.CanceledFailure;
30-
import io.temporal.testing.TracingWorkerInterceptor;
3130
import io.temporal.workflow.shared.SDKTestWorkflowRule;
3231
import io.temporal.workflow.shared.TestActivities;
3332
import java.time.Duration;
@@ -41,12 +40,10 @@ public class ChildWorkflowCancellationTest {
4140

4241
@Rule
4342
public SDKTestWorkflowRule testWorkflowRule =
44-
SDKTestWorkflowRule.newBuilder()
45-
.setWorkflowTypes(TestParentWorkflowImpl.class, TestChildWorkflowImpl.class)
46-
.setActivityImplementations(activitiesImpl)
47-
.setWorkerInterceptors(
48-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
49-
.build();
43+
SDKTestWorkflowRule.newBuilder()
44+
.setWorkflowTypes(TestParentWorkflowImpl.class, TestChildWorkflowImpl.class)
45+
.setActivityImplementations(activitiesImpl)
46+
.build();
5047

5148
@Test
5249
public void testChildWorkflowWaitCancellationRequested() {

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowExecutionPromiseHandlerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.temporal.client.WorkflowClient;
2626
import io.temporal.client.WorkflowOptions;
2727
import io.temporal.testing.TestWorkflowRule;
28-
import io.temporal.testing.TracingWorkerInterceptor;
2928
import io.temporal.workflow.shared.TestActivities;
3029
import io.temporal.workflow.shared.TestWorkflows;
3130
import java.time.Duration;
@@ -42,8 +41,6 @@ public class ChildWorkflowExecutionPromiseHandlerTest {
4241
TestWorkflowRule.newBuilder()
4342
.setWorkflowTypes(TestNamedChild.class, TestChildWorkflowExecutionPromiseHandler.class)
4443
.setActivityImplementations(activitiesImpl)
45-
.setWorkerInterceptors(
46-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
4744
.build();
4845

4946
/** Tests that handler of the WorkflowExecution promise is executed in a workflow thread. */

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowRetryTest.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
import io.temporal.common.interceptors.WorkflowClientInterceptorBase;
3333
import io.temporal.failure.ApplicationFailure;
3434
import io.temporal.failure.ChildWorkflowFailure;
35-
import io.temporal.testing.TracingWorkerInterceptor;
3635
import io.temporal.testing.WorkflowReplayer;
3736
import io.temporal.worker.WorkflowImplementationOptions;
3837
import io.temporal.workflow.shared.SDKTestWorkflowRule;
38+
import io.temporal.workflow.shared.TestActivities;
3939
import io.temporal.workflow.shared.TestWorkflows;
4040
import java.time.Duration;
4141
import java.util.concurrent.atomic.AtomicReference;
@@ -46,36 +46,34 @@
4646
public class ChildWorkflowRetryTest {
4747

4848
private final AtomicReference<String> lastStartedWorkflowType = new AtomicReference<>();
49-
private final WorkflowTest.AngryChildActivityImpl angryChildActivity =
50-
new WorkflowTest.AngryChildActivityImpl();
49+
private final TestActivities.AngryChildActivityImpl angryChildActivity =
50+
new TestActivities.AngryChildActivityImpl();
5151

5252
@Rule
5353
public SDKTestWorkflowRule testWorkflowRule =
54-
SDKTestWorkflowRule.newBuilder()
55-
.setWorkflowTypes(
56-
WorkflowImplementationOptions.newBuilder()
57-
.setFailWorkflowExceptionTypes(UnsupportedOperationException.class)
58-
.build(),
59-
TestChildWorkflowRetryWorkflow.class,
60-
WorkflowTest.AngryChild.class)
61-
.setActivityImplementations(angryChildActivity)
62-
.setWorkerInterceptors(
63-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
64-
.setWorkflowClientOptions(
65-
WorkflowClientOptions.newBuilder()
66-
.setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM)
67-
.setInterceptors(
68-
new WorkflowClientInterceptorBase() {
69-
@Override
70-
public WorkflowStub newUntypedWorkflowStub(
71-
String workflowType, WorkflowOptions options, WorkflowStub next) {
72-
lastStartedWorkflowType.set(workflowType);
73-
return next;
74-
}
75-
})
76-
.setNamespace(NAMESPACE)
77-
.build())
78-
.build();
54+
SDKTestWorkflowRule.newBuilder()
55+
.setWorkflowTypes(
56+
WorkflowImplementationOptions.newBuilder()
57+
.setFailWorkflowExceptionTypes(UnsupportedOperationException.class)
58+
.build(),
59+
TestChildWorkflowRetryWorkflow.class,
60+
WorkflowTest.AngryChild.class)
61+
.setActivityImplementations(angryChildActivity)
62+
.setWorkflowClientOptions(
63+
WorkflowClientOptions.newBuilder()
64+
.setBinaryChecksum(SDKTestWorkflowRule.BINARY_CHECKSUM)
65+
.setInterceptors(
66+
new WorkflowClientInterceptorBase() {
67+
@Override
68+
public WorkflowStub newUntypedWorkflowStub(
69+
String workflowType, WorkflowOptions options, WorkflowStub next) {
70+
lastStartedWorkflowType.set(workflowType);
71+
return next;
72+
}
73+
})
74+
.setNamespace(NAMESPACE)
75+
.build())
76+
.build();
7977

8078
@Test
8179
public void testChildWorkflowRetry() {

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121

2222
import static org.junit.Assert.assertEquals;
2323

24-
import io.temporal.client.WorkflowOptions;
25-
import io.temporal.testing.TestWorkflowRule;
26-
import io.temporal.testing.TracingWorkerInterceptor;
24+
import io.temporal.workflow.shared.SDKTestWorkflowRule;
2725
import io.temporal.workflow.shared.TestActivities;
2826
import io.temporal.workflow.shared.TestWorkflows;
29-
import java.time.Duration;
3027
import java.util.UUID;
3128
import org.junit.Rule;
3229
import org.junit.Test;
@@ -38,29 +35,18 @@ public class ChildWorkflowTest {
3835
new TestActivities.TestActivitiesImpl(null);
3936

4037
@Rule
41-
public TestWorkflowRule testWorkflowRule =
42-
TestWorkflowRule.newBuilder()
38+
public SDKTestWorkflowRule testWorkflowRule =
39+
SDKTestWorkflowRule.newBuilder()
4340
.setWorkflowTypes(
4441
TestParentWorkflow.class, TestNamedChild.class, WorkflowTest.TestChild.class)
4542
.setActivityImplementations(activitiesImpl)
46-
.setWorkerInterceptors(
47-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
4843
.build();
4944

5045
@Test
5146
public void testChildWorkflow() {
5247
child2Id = UUID.randomUUID().toString();
53-
54-
WorkflowOptions options =
55-
WorkflowOptions.newBuilder()
56-
.setWorkflowRunTimeout(Duration.ofSeconds(200))
57-
.setWorkflowTaskTimeout(Duration.ofSeconds(60))
58-
.setTaskQueue(testWorkflowRule.getTaskQueue())
59-
.build();
6048
TestWorkflows.TestWorkflow1 client =
61-
testWorkflowRule
62-
.getWorkflowClient()
63-
.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options);
49+
testWorkflowRule.newWorkflowStub200sTimeoutOptions(TestWorkflows.TestWorkflow1.class);
6450
assertEquals("HELLO WORLD!", client.execute(testWorkflowRule.getTaskQueue()));
6551
}
6652

temporal-sdk/src/test/java/io/temporal/workflow/ChildWorkflowTimeoutTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import com.google.common.base.Throwables;
25-
import io.temporal.client.WorkflowOptions;
26-
import io.temporal.testing.TestWorkflowRule;
27-
import io.temporal.testing.TracingWorkerInterceptor;
25+
import io.temporal.workflow.shared.SDKTestWorkflowRule;
2826
import io.temporal.workflow.shared.TestActivities;
2927
import io.temporal.workflow.shared.TestWorkflows;
3028
import java.time.Duration;
@@ -37,26 +35,16 @@ public class ChildWorkflowTimeoutTest {
3735
new TestActivities.TestActivitiesImpl(null);
3836

3937
@Rule
40-
public TestWorkflowRule testWorkflowRule =
41-
TestWorkflowRule.newBuilder()
38+
public SDKTestWorkflowRule testWorkflowRule =
39+
SDKTestWorkflowRule.newBuilder()
4240
.setWorkflowTypes(TestParentWorkflowWithChildTimeout.class, WorkflowTest.TestChild.class)
4341
.setActivityImplementations(activitiesImpl)
44-
.setWorkerInterceptors(
45-
new TracingWorkerInterceptor(new TracingWorkerInterceptor.FilteredTrace()))
4642
.build();
4743

4844
@Test
4945
public void testChildWorkflowTimeout() {
50-
WorkflowOptions options =
51-
WorkflowOptions.newBuilder()
52-
.setWorkflowRunTimeout(Duration.ofSeconds(200))
53-
.setWorkflowTaskTimeout(Duration.ofSeconds(60))
54-
.setTaskQueue(testWorkflowRule.getTaskQueue())
55-
.build();
5646
TestWorkflows.TestWorkflow1 client =
57-
testWorkflowRule
58-
.getWorkflowClient()
59-
.newWorkflowStub(TestWorkflows.TestWorkflow1.class, options);
47+
testWorkflowRule.newWorkflowStub200sTimeoutOptions(TestWorkflows.TestWorkflow1.class);
6048
String result = client.execute(testWorkflowRule.getTaskQueue());
6149
assertTrue(result, result.contains("ChildWorkflowFailure"));
6250
assertTrue(result, result.contains("TimeoutFailure"));

0 commit comments

Comments
 (0)