Skip to content

Commit b68449d

Browse files
committed
fix: Fix flaky test ScheduledRetryingExecutorTest.testCancelOuterFutureAfterStart.
1 parent c8e3941 commit b68449d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import com.google.api.core.NanoClock;
4242
import com.google.api.gax.retrying.FailingCallable.CustomException;
4343
import com.google.api.gax.rpc.testing.FakeCallContext;
44+
45+
import java.util.Optional;
4446
import java.util.concurrent.CancellationException;
4547
import java.util.concurrent.ExecutionException;
4648
import java.util.concurrent.Executors;
@@ -195,13 +197,13 @@ void testCancelGetAttempt(boolean withCustomRetrySettings) throws Exception {
195197
setUp(withCustomRetrySettings);
196198
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
197199
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
198-
final int maxRetries = 100;
200+
final int maxRetries = 20;
199201

200202
FailingCallable callable = new FailingCallable(maxRetries - 1, "request", "SUCCESS", tracer);
201203
RetrySettings retrySettings =
202204
FAST_RETRY_SETTINGS
203205
.toBuilder()
204-
.setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L))
206+
.setTotalTimeoutDuration(java.time.Duration.ofMillis(5000L))
205207
.setMaxAttempts(maxRetries)
206208
.build();
207209

@@ -259,10 +261,10 @@ void testCancelOuterFutureAfterStart() throws Exception {
259261
.toBuilder()
260262
// These params were selected to ensure that future tries to run and fail (at least
261263
// once) but does not complete before it is cancelled. Assuming no computation time,
262-
// it would take 25 + 100 + 400 + 1000 = 1525ms for the future to complete, which should
264+
// it would take 2500 + 10000 + 10000 + 10000 = 32500ms for the future to complete, which should
263265
// be more than enough time to cancel the future.
264-
.setInitialRetryDelayDuration(java.time.Duration.ofMillis(25L))
265-
.setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000L))
266+
.setInitialRetryDelayDuration(java.time.Duration.ofMillis(2500L))
267+
.setMaxRetryDelayDuration(java.time.Duration.ofMillis(10000L))
266268
.setRetryDelayMultiplier(4.0)
267269
.setTotalTimeoutDuration(java.time.Duration.ofMillis(60000L))
268270
// Set this test to not use jitter as the randomized retry delay (RRD) may introduce

0 commit comments

Comments
 (0)