Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ to docs, or any other relevant information.
project-scoped custom roles, and caller rate limits.

### Fixed
- The in-memory test server now reports the scheduled time of activity retries after their backoff.
- Autoscaling workflow pollers now prioritize meaningful sticky backlog up to the sticky pool's
target and use advertised slot capacity to balance sticky and non-sticky admission. Without an
advertised maximum, additional polls of one queue type wait until the other has an active poll.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.temporal.activity;

import static org.junit.Assert.assertTrue;

import io.temporal.common.RetryOptions;
import io.temporal.failure.ApplicationFailure;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import io.temporal.workflow.Workflow;
import io.temporal.workflow.shared.TestActivities;
import io.temporal.workflow.shared.TestWorkflows;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Rule;
import org.junit.Test;

public class ActivityRetryScheduledTimestampTest {
private static final Duration INITIAL_INTERVAL = Duration.ofSeconds(10);

private final AtomicLong firstScheduled = new AtomicLong();
private final AtomicLong retryScheduled = new AtomicLong();

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(RetryWorkflow.class)
.setActivityImplementations(
(TestActivities.NoArgsActivity) this::recordScheduledTimestamp)
.build();

@Test
public void retryScheduledTimestampIncludesBackoff() {
testWorkflowRule.newWorkflowStub(TestWorkflows.NoArgsWorkflow.class).execute();

long elapsed = retryScheduled.get() - firstScheduled.get();
assertTrue(
"Elapsed time between scheduled attempts: " + elapsed + " ms",
elapsed >= INITIAL_INTERVAL.toMillis());
}

private void recordScheduledTimestamp() {
ActivityInfo info = Activity.getExecutionContext().getInfo();
if (info.getAttempt() == 1) {
firstScheduled.set(info.getCurrentAttemptScheduledTimestamp());
throw ApplicationFailure.newFailure("Retry this activity", "TestFailure");
}
retryScheduled.set(info.getCurrentAttemptScheduledTimestamp());
}

public static class RetryWorkflow implements TestWorkflows.NoArgsWorkflow {
@Override
public void execute() {
Workflow.newActivityStub(
TestActivities.NoArgsActivity.class,
ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(5))
.setRetryOptions(
RetryOptions.newBuilder()
.setInitialInterval(INITIAL_INTERVAL)
.setMaximumAttempts(2)
.build())
.build())
.execute();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,6 @@ private static RetryState attemptActivityRetry(
data.retryState = nextAttempt;
data.lastAttemptCompleteTime = ctx.currentTime();
task.setAttempt(nextAttempt.getAttempt());
task.setCurrentAttemptScheduledTime(ctx.currentTime());
});
} else {
data.nextBackoffInterval = Durations.ZERO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,11 @@ private void addActivityRetryTimer(RequestContext ctx, StateMachine<ActivityTask
try {
// TODO this lock is getting releases somewhere on the activity completion.
// We should rework it on passing the lockHandle downstream and using it for the release
update(ctx1 -> ctx1.addActivityTask(data.activityTask));
update(
ctx1 -> {
data.activityTask.getTask().setCurrentAttemptScheduledTime(ctx1.currentTime());
ctx1.addActivityTask(data.activityTask);
});
} catch (StatusRuntimeException e) {
// NOT_FOUND is expected as timers are not removed
if (e.getStatus().getCode() != Status.Code.NOT_FOUND) {
Expand Down