Skip to content

Commit d798e6d

Browse files
mfateevvancexu
authored andcommitted
Fixed exception propagation from child workflows (#400)
1 parent d65c3e5 commit d798e6d

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

src/main/java/com/uber/cadence/internal/sync/SyncDecisionContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ private RuntimeException mapChildWorkflowException(Exception failure) {
418418
return (CancellationException) failure;
419419
}
420420
if (failure instanceof ChildWorkflowException) {
421-
throw (ChildWorkflowException) failure;
421+
return (ChildWorkflowException) failure;
422422
}
423423
if (!(failure instanceof ChildWorkflowTaskFailedException)) {
424-
throw new IllegalArgumentException("Unexpected exception type: ", failure);
424+
return new IllegalArgumentException("Unexpected exception type: ", failure);
425425
}
426426
ChildWorkflowTaskFailedException taskFailed = (ChildWorkflowTaskFailedException) failure;
427427
String causeClassName = taskFailed.getReason();
@@ -672,7 +672,7 @@ private RuntimeException mapSignalWorkflowException(Exception failure) {
672672
}
673673

674674
if (!(failure instanceof SignalExternalWorkflowException)) {
675-
throw new IllegalArgumentException("Unexpected exception type: ", failure);
675+
return new IllegalArgumentException("Unexpected exception type: ", failure);
676676
}
677677
return (SignalExternalWorkflowException) failure;
678678
}

src/test/java/com/uber/cadence/workflow/WorkflowTest.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ public void testTimerCallbackBlocked() {
25572557
public interface ITestChild {
25582558

25592559
@WorkflowMethod
2560-
String execute(String arg);
2560+
String execute(String arg, int delay);
25612561
}
25622562

25632563
public interface ITestNamedChild {
@@ -2581,17 +2581,39 @@ public TestParentWorkflow() {
25812581

25822582
@Override
25832583
public String execute(String taskList) {
2584-
Promise<String> r1 = Async.function(child1::execute, "Hello ");
2584+
Promise<String> r1 = Async.function(child1::execute, "Hello ", 0);
25852585
String r2 = child2.execute("World!");
25862586
assertEquals(child2Id, Workflow.getWorkflowExecution(child2).get().getWorkflowId());
25872587
return r1.get() + r2;
25882588
}
25892589
}
25902590

2591+
public static class TestParentWorkflowWithChildTimeout implements TestWorkflow1 {
2592+
2593+
private final ITestChild child;
2594+
2595+
public TestParentWorkflowWithChildTimeout() {
2596+
ChildWorkflowOptions.Builder options = new ChildWorkflowOptions.Builder();
2597+
options.setExecutionStartToCloseTimeout(Duration.ofSeconds(1));
2598+
child = Workflow.newChildWorkflowStub(ITestChild.class, options.build());
2599+
}
2600+
2601+
@Override
2602+
public String execute(String taskList) {
2603+
try {
2604+
child.execute("Hello ", (int) Duration.ofDays(1).toMillis());
2605+
} catch (Exception e) {
2606+
return e.getClass().getSimpleName();
2607+
}
2608+
throw new RuntimeException("not reachable");
2609+
}
2610+
}
2611+
25912612
public static class TestChild implements ITestChild {
25922613

25932614
@Override
2594-
public String execute(String arg) {
2615+
public String execute(String arg, int delay) {
2616+
Workflow.sleep(delay);
25952617
return arg.toUpperCase();
25962618
}
25972619
}
@@ -2617,6 +2639,19 @@ public void testChildWorkflow() {
26172639
assertEquals("HELLO WORLD!", client.execute(taskList));
26182640
}
26192641

2642+
@Test
2643+
public void testChildWorkflowTimeout() {
2644+
child2Id = UUID.randomUUID().toString();
2645+
startWorkerFor(TestParentWorkflowWithChildTimeout.class, TestChild.class);
2646+
2647+
WorkflowOptions.Builder options = new WorkflowOptions.Builder();
2648+
options.setExecutionStartToCloseTimeout(Duration.ofSeconds(200));
2649+
options.setTaskStartToCloseTimeout(Duration.ofSeconds(60));
2650+
options.setTaskList(taskList);
2651+
TestWorkflow1 client = workflowClient.newWorkflowStub(TestWorkflow1.class, options.build());
2652+
assertEquals("ChildWorkflowTimedOutException", client.execute(taskList));
2653+
}
2654+
26202655
private static String childReexecuteId = UUID.randomUUID().toString();
26212656

26222657
public interface WorkflowIdReusePolicyParent {
@@ -2726,7 +2761,7 @@ public String execute(String taskList) {
27262761
.build();
27272762
child = Workflow.newChildWorkflowStub(ITestChild.class, options);
27282763

2729-
return child.execute(taskList);
2764+
return child.execute(taskList, 0);
27302765
}
27312766
}
27322767

@@ -2753,7 +2788,7 @@ public long getInvocationCount() {
27532788
public static class AngryChild implements ITestChild {
27542789

27552790
@Override
2756-
public String execute(String taskList) {
2791+
public String execute(String taskList, int delay) {
27572792
AngryChildActivity activity =
27582793
Workflow.newActivityStub(
27592794
AngryChildActivity.class,
@@ -3007,7 +3042,7 @@ public String execute(String taskList) {
30073042
.build())
30083043
.build();
30093044
child = Workflow.newChildWorkflowStub(ITestChild.class, options);
3010-
return Async.function(child::execute, taskList).get();
3045+
return Async.function(child::execute, taskList, 0).get();
30113046
}
30123047
}
30133048

0 commit comments

Comments
 (0)