Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ public void executeLocalActivityOverLocalRetryThreshold(
input,
originalScheduledTime,
laException.getLastAttempt() + 1,
laException.getFailure(),
// Carry the attempt failure, not the local ActivityFailure wrapper.
laException.getFailure().getCause(),
result);
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.enums.v1.EventType;
import io.temporal.api.enums.v1.RetryState;
import io.temporal.api.enums.v1.TimeoutType;
import io.temporal.api.history.v1.HistoryEvent;
import io.temporal.client.WorkflowException;
import io.temporal.client.WorkflowStub;
import io.temporal.common.RetryOptions;
import io.temporal.failure.ActivityFailure;
import io.temporal.failure.TimeoutFailure;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import io.temporal.worker.Worker;
import io.temporal.workflow.Workflow;
Expand All @@ -26,6 +28,8 @@

public class LocalActivityRetryOverLocalBackoffThresholdTest {

private static final int TIMEOUT_ATTEMPTS = 3;

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
Expand Down Expand Up @@ -96,6 +100,35 @@ public void maxAttemptDecreasedOnRetryWakeUp() {
controlledActivity.verifyAttempts();
}

@Test
public void repeatedTimeoutsDoNotBuildAnUnboundedFailureChain() {
Worker worker = testWorkflowRule.getWorker();
ControlledActivityImpl activity =
new ControlledActivityImpl(
Collections.singletonList(ControlledActivityImpl.Outcome.SLEEP), TIMEOUT_ATTEMPTS, 1);
worker.registerActivitiesImplementations(activity);
worker.registerWorkflowImplementationTypes(TimingOutWorkflowImpl.class);
testWorkflowRule.getTestEnvironment().start();

TestWorkflows.TestWorkflow1 workflowStub =
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class);

WorkflowException e =
assertThrows(
WorkflowException.class, () -> workflowStub.execute(testWorkflowRule.getTaskQueue()));
assertTrue(e.getCause() instanceof ActivityFailure);
ActivityFailure activityFailure = (ActivityFailure) e.getCause();
assertEquals(RetryState.RETRY_STATE_MAXIMUM_ATTEMPTS_REACHED, activityFailure.getRetryState());
assertTrue(activityFailure.getCause() instanceof TimeoutFailure);
TimeoutFailure timeoutFailure = (TimeoutFailure) activityFailure.getCause();
assertEquals(TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE, timeoutFailure.getTimeoutType());
assertTrue(timeoutFailure.getCause() instanceof TimeoutFailure);
TimeoutFailure previousTimeoutFailure = (TimeoutFailure) timeoutFailure.getCause();
assertEquals(TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE, previousTimeoutFailure.getTimeoutType());
assertNull(previousTimeoutFailure.getCause());
activity.verifyAttempts();
}

public static class TestWorkflowImpl implements TestWorkflows.TestWorkflow1 {

@Override
Expand Down Expand Up @@ -144,4 +177,25 @@ public String execute(String taskQueue) {
return "ignored";
}
}

public static class TimingOutWorkflowImpl implements TestWorkflows.TestWorkflow1 {

@Override
public String execute(String taskQueue) {
LocalActivityOptions options =
LocalActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofMillis(10))
.setLocalRetryThreshold(Duration.ofMillis(1))
.setRetryOptions(
RetryOptions.newBuilder()
.setInitialInterval(Duration.ofMillis(2))
.setBackoffCoefficient(1)
.setMaximumAttempts(TIMEOUT_ATTEMPTS)
.build())
.build();
TestActivities.NoArgsReturnsStringActivity activity =
Workflow.newLocalActivityStub(TestActivities.NoArgsReturnsStringActivity.class, options);
return activity.execute();
}
}
}
Loading