Skip to content

Commit b3c096d

Browse files
Add check for duplicate handler start
1 parent 18a9894 commit b3c096d

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

temporal-sdk/src/test/java/io/temporal/workflow/nexus/GenericHandlerDoubleStartTest.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.temporal.nexus.TemporalOperationHandler;
1414
import io.temporal.testing.internal.SDKTestWorkflowRule;
1515
import io.temporal.workflow.*;
16-
import io.temporal.workflow.shared.TestMultiArgWorkflowFunctions;
1716
import io.temporal.workflow.shared.TestWorkflows;
1817
import java.time.Duration;
1918
import org.junit.Assert;
@@ -24,8 +23,7 @@ public class GenericHandlerDoubleStartTest {
2423
@Rule
2524
public SDKTestWorkflowRule testWorkflowRule =
2625
SDKTestWorkflowRule.newBuilder()
27-
.setWorkflowTypes(
28-
TestNexus.class, TestMultiArgWorkflowFunctions.TestMultiArgWorkflowImpl.class)
26+
.setWorkflowTypes(TestNexus.class, BlockingWorkflowImpl.class)
2927
.setNexusServiceImplementation(new TestNexusServiceImpl())
3028
.build();
3129

@@ -68,7 +66,23 @@ public String execute(String input) {
6866

6967
TestNexusServiceDoubleStart serviceStub =
7068
Workflow.newNexusServiceStub(TestNexusServiceDoubleStart.class, serviceOptions);
71-
return serviceStub.operation("input");
69+
return serviceStub.operation(input);
70+
}
71+
}
72+
73+
@WorkflowInterface
74+
public interface BlockingWorkflow {
75+
@WorkflowMethod
76+
String execute(String input);
77+
}
78+
79+
public static class BlockingWorkflowImpl implements BlockingWorkflow {
80+
@Override
81+
public String execute(String input) {
82+
// Block forever so the nexus operation doesn't complete via callback
83+
// before the handler error propagates
84+
Workflow.await(() -> false);
85+
return input;
7286
}
7387
}
7488

@@ -84,18 +98,18 @@ public class TestNexusServiceImpl {
8498
public OperationHandler<String, String> operation() {
8599
return TemporalOperationHandler.create(
86100
(context, client, input) -> {
87-
// First start should succeed
101+
// First start should succeed but the workflow blocks indefinitely
88102
client.startWorkflow(
89-
TestMultiArgWorkflowFunctions.Test1ArgWorkflowFunc.class,
90-
TestMultiArgWorkflowFunctions.Test1ArgWorkflowFunc::func1,
103+
BlockingWorkflow.class,
104+
BlockingWorkflow::execute,
91105
input,
92106
WorkflowOptions.newBuilder()
93107
.setWorkflowId("double-start-first-" + context.getService())
94108
.build());
95109
// Second start should throw
96110
return client.startWorkflow(
97-
TestMultiArgWorkflowFunctions.Test1ArgWorkflowFunc.class,
98-
TestMultiArgWorkflowFunctions.Test1ArgWorkflowFunc::func1,
111+
BlockingWorkflow.class,
112+
BlockingWorkflow::execute,
99113
input,
100114
WorkflowOptions.newBuilder()
101115
.setWorkflowId("double-start-second-" + context.getService())

0 commit comments

Comments
 (0)