Skip to content

Commit 2322bd0

Browse files
authored
Fix test server to return INVALID_ARGUMENT for UNHANDLED_COMMAND (#2757)
The real Temporal server returns INVALID_ARGUMENT error when a workflow task has unhandled commands. The test server was silently recording the failure in history but returning success to the caller, causing the SDK to apply completion metrics before learning the task was rejected. This fix makes the test server throw INVALID_ARGUMENT: UnhandledCommand to match real server behavior, preventing double-counted metrics. Also adds registry.clear() in MetricsTest setUp for clean state.
1 parent 2ff9c2c commit 2322bd0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

temporal-sdk/src/test/java/io/temporal/client/functional/MetricsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MetricsTest {
6363

6464
@Before
6565
public void setUp() {
66+
registry.clear();
6667
tagsNamespaceQueue =
6768
replaceTags(TAGS_NAMESPACE, MetricsTag.TASK_QUEUE, testWorkflowRule.getTaskQueue());
6869
}

temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowMutableStateImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,16 @@ public void completeWorkflowTask(
488488

489489
if (unhandledCommand(request) || unhandledMessages(request)) {
490490
// Fail the workflow task if there are new events or messages and a command tries to
491-
// complete the
492-
// workflow
491+
// complete the workflow. Record the failure in history, then throw an error to the
492+
// caller (matching real server behavior).
493493
failWorkflowTaskWithAReason(
494494
WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND,
495495
null,
496496
ctx,
497497
request,
498498
false);
499+
ctx.setExceptionIfEmpty(
500+
Status.INVALID_ARGUMENT.withDescription("UnhandledCommand").asRuntimeException());
499501
return;
500502
}
501503

0 commit comments

Comments
 (0)