Skip to content

Commit 333a15e

Browse files
committed
Fix tests for Temporal Server 1.31.0 behavior changes
Activity timeout tests now expect RETRY_STATE_TIMEOUT unconditionally, matching the server fix for temporalio/temporal#3667. GrpcMessageTooLarge tests expect TerminatedFailure with FORCE_CLOSE_COMMAND cause instead of TimeoutFailure. Updated test server to terminate workflows on GRPC_MESSAGE_TOO_LARGE failures, aligning with real server behavior.
1 parent 488e7e6 commit 333a15e

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import io.temporal.api.history.v1.HistoryEvent;
1010
import io.temporal.client.*;
1111
import io.temporal.failure.ApplicationFailure;
12-
import io.temporal.failure.TimeoutFailure;
12+
import io.temporal.failure.TerminatedFailure;
1313
import io.temporal.internal.replay.ReplayWorkflowTaskHandler;
1414
import io.temporal.internal.retryer.GrpcMessageTooLargeException;
1515
import io.temporal.internal.worker.PollerOptions;
@@ -71,7 +71,7 @@ public void activityStartTooLarge() {
7171

7272
WorkflowFailedException e =
7373
assertThrows(WorkflowFailedException.class, () -> workflow.execute(""));
74-
assertTrue(e.getCause() instanceof TimeoutFailure);
74+
assertTrue(e.getCause() instanceof TerminatedFailure);
7575

7676
String workflowId = WorkflowStub.fromTyped(workflow).getExecution().getWorkflowId();
7777
assertTrue(
@@ -83,7 +83,7 @@ public void activityStartTooLarge() {
8383
workflowId, EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED);
8484
assertEquals(1, events.size());
8585
assertEquals(
86-
WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_GRPC_MESSAGE_TOO_LARGE,
86+
WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_FORCE_CLOSE_COMMAND,
8787
events.get(0).getWorkflowTaskFailedEventAttributes().getCause());
8888
}
8989

@@ -97,14 +97,14 @@ public void workflowFailureTooLarge() {
9797
WorkflowFailedException e =
9898
assertThrows(WorkflowFailedException.class, () -> workflow.execute(""));
9999

100-
assertTrue(e.getCause() instanceof TimeoutFailure);
100+
assertTrue(e.getCause() instanceof TerminatedFailure);
101101
String workflowId = WorkflowStub.fromTyped(workflow).getExecution().getWorkflowId();
102102
List<HistoryEvent> events =
103103
failureWorkflowRule.getHistoryEvents(
104104
workflowId, EventType.EVENT_TYPE_WORKFLOW_TASK_FAILED);
105105
assertEquals(1, events.size());
106106
assertEquals(
107-
WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_GRPC_MESSAGE_TOO_LARGE,
107+
WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_FORCE_CLOSE_COMMAND,
108108
events.get(0).getWorkflowTaskFailedEventAttributes().getCause());
109109
}
110110
}

temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityTimeoutTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.temporal.failure.ActivityFailure;
1616
import io.temporal.failure.ApplicationFailure;
1717
import io.temporal.failure.TimeoutFailure;
18-
import io.temporal.testing.internal.ExternalServiceTestConfigurator;
1918
import io.temporal.testing.internal.SDKTestWorkflowRule;
2019
import io.temporal.worker.Worker;
2120
import io.temporal.worker.WorkerOptions;
@@ -294,12 +293,7 @@ public void scheduleToStartTimeout(boolean local) throws InterruptedException {
294293

295294
MatcherAssert.assertThat(
296295
activityFailure.getMessage(), CoreMatchers.containsString("Activity task timed out"));
297-
if (ExternalServiceTestConfigurator.isUseExternalService() && !local) {
298-
// https://github.com/temporalio/temporal/issues/3667
299-
assertEquals(RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, activityFailure.getRetryState());
300-
} else {
301-
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
302-
}
296+
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
303297

304298
assertTrue(activityFailure.getCause() instanceof TimeoutFailure);
305299
assertEquals(
@@ -567,12 +561,7 @@ public void scheduleToCloseTimeout_timingOutActivity(boolean local) {
567561
assertTrue(e.getCause() instanceof ActivityFailure);
568562
ActivityFailure activityFailure = (ActivityFailure) e.getCause();
569563

570-
if (ExternalServiceTestConfigurator.isUseExternalService() && !local) {
571-
// https://github.com/temporalio/temporal/issues/3667
572-
assertEquals(RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, activityFailure.getRetryState());
573-
} else {
574-
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
575-
}
564+
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
576565

577566
MatcherAssert.assertThat(
578567
activityFailure.getMessage(), CoreMatchers.containsString("Activity task timed out"));
@@ -618,12 +607,7 @@ public void scheduleToCloseTimeout_failing_timingOutActivity(boolean local) {
618607
assertTrue(e.getCause() instanceof ActivityFailure);
619608
ActivityFailure activityFailure = (ActivityFailure) e.getCause();
620609

621-
if (ExternalServiceTestConfigurator.isUseExternalService() && !local) {
622-
// https://github.com/temporalio/temporal/issues/3667
623-
assertEquals(RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, activityFailure.getRetryState());
624-
} else {
625-
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
626-
}
610+
assertEquals(RetryState.RETRY_STATE_TIMEOUT, activityFailure.getRetryState());
627611

628612
MatcherAssert.assertThat(
629613
activityFailure.getMessage(), CoreMatchers.containsString("Activity task timed out"));

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,12 +1288,34 @@ private void processFailWorkflowTask(
12881288
// server drops failures after the second attempt and let the workflow task timeout
12891289
return;
12901290
}
1291+
boolean isGrpcMessageTooLarge =
1292+
request.getCause()
1293+
== WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_GRPC_MESSAGE_TOO_LARGE;
1294+
if (isGrpcMessageTooLarge) {
1295+
// The real server records a FORCE_CLOSE_COMMAND cause and terminates the workflow
1296+
request =
1297+
request.toBuilder()
1298+
.setCause(WorkflowTaskFailedCause.WORKFLOW_TASK_FAILED_CAUSE_FORCE_CLOSE_COMMAND)
1299+
.build();
1300+
}
12911301
workflowTaskStateMachine.action(Action.FAIL, ctx, request, 0);
12921302
for (RequestContext deferredCtx : workflowTaskStateMachine.getData().bufferedEvents) {
12931303
ctx.add(deferredCtx);
12941304
}
12951305
workflowTaskStateMachine.getData().bufferedEvents.clear();
1296-
scheduleWorkflowTask(ctx);
1306+
if (isGrpcMessageTooLarge) {
1307+
workflow.action(
1308+
Action.TERMINATE,
1309+
ctx,
1310+
TerminateWorkflowExecutionRequest.newBuilder()
1311+
.setReason("GrpcMessageTooLarge")
1312+
.build(),
1313+
0);
1314+
workflowTaskStateMachine.getData().workflowCompleted = true;
1315+
processWorkflowCompletionCallbacks(ctx);
1316+
} else {
1317+
scheduleWorkflowTask(ctx);
1318+
}
12971319
ctx.unlockTimer("failWorkflowTask"); // Unlock timer associated with the workflow task
12981320
}
12991321

0 commit comments

Comments
 (0)