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
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ BackoffInterval getBackoffIntervalInSeconds(

Timestamp nextScheduleTime =
Timestamps.add(currentTime, ProtobufTimeUtils.toProtoDuration(backoffDuration));
if (expirationTime.getNanos() != 0
&& Timestamps.compare(nextScheduleTime, expirationTime) > 0) {
if (Timestamps.compare(nextScheduleTime, expirationTime) > 0) {
return new BackoffInterval(RetryState.RETRY_STATE_TIMEOUT);
}
return new BackoffInterval(backoffDuration);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.temporal.internal.testservice;

import static org.junit.Assert.assertEquals;

import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Durations;
import com.google.protobuf.util.Timestamps;
import io.temporal.api.common.v1.RetryPolicy;
import io.temporal.api.enums.v1.RetryState;
import java.time.Duration;
import java.util.Optional;
import org.junit.Test;

public class TestServiceRetryStateTest {

private static final RetryPolicy RETRY_POLICY =
RetryPolicy.newBuilder()
.setInitialInterval(Durations.fromSeconds(10))
.setBackoffCoefficient(1.0)
.build();

@Test
public void expirationOnWholeSecondTimesOut() {
// A deadline with a zero nanos field must still be honored.
Timestamp now = Timestamps.fromSeconds(1_000);
Timestamp expiration = Timestamps.fromSeconds(1_005);
TestServiceRetryState state = new TestServiceRetryState(RETRY_POLICY, expiration);

TestServiceRetryState.BackoffInterval backoff =
state.getBackoffIntervalInSeconds(Optional.empty(), now, Optional.empty());

assertEquals(RetryState.RETRY_STATE_TIMEOUT, backoff.getRetryState());
}

@Test
public void expirationWithSubsecondTimesOut() {
Timestamp now = Timestamps.fromMillis(1_000_500);
Timestamp expiration = Timestamps.fromMillis(1_005_500);
TestServiceRetryState state = new TestServiceRetryState(RETRY_POLICY, expiration);

TestServiceRetryState.BackoffInterval backoff =
state.getBackoffIntervalInSeconds(Optional.empty(), now, Optional.empty());

assertEquals(RetryState.RETRY_STATE_TIMEOUT, backoff.getRetryState());
}

@Test
public void unsetExpirationNeverTimesOut() {
Timestamp now = Timestamps.fromSeconds(1_000);
TestServiceRetryState state =
new TestServiceRetryState(RETRY_POLICY, Timestamp.getDefaultInstance());

TestServiceRetryState.BackoffInterval backoff =
state.getBackoffIntervalInSeconds(Optional.empty(), now, Optional.empty());

assertEquals(RetryState.RETRY_STATE_IN_PROGRESS, backoff.getRetryState());
assertEquals(Duration.ofSeconds(10), backoff.getInterval());
}

@Test
public void retryWithinExpirationProceeds() {
Timestamp now = Timestamps.fromSeconds(1_000);
Timestamp expiration = Timestamps.fromSeconds(1_060);
TestServiceRetryState state = new TestServiceRetryState(RETRY_POLICY, expiration);

TestServiceRetryState.BackoffInterval backoff =
state.getBackoffIntervalInSeconds(Optional.empty(), now, Optional.empty());

assertEquals(RetryState.RETRY_STATE_IN_PROGRESS, backoff.getRetryState());
assertEquals(Duration.ofSeconds(10), backoff.getInterval());
}
}
Loading