Skip to content

Commit e73740d

Browse files
authoredNov 6, 2024
fix: Fix flaky test ScheduledRetryingExecutorTest.testCancelOuterFutureAfterStart (#3335)
The test was flaky because the [Thread.sleep(150)](https://github.com/googleapis/sdk-platform-java/blob/b031b18a9bb35b77ca21d3665217aa4c219ced57/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java#L288) does not guarantee the main thread would wake up after exactly 150ms, it might take much longer if the resource is limited on the machine or we are running tests in parallel. Hence if the thread sleeps more than [1525ms](https://github.com/googleapis/sdk-platform-java/blob/0cddadb8ad3eddfffa356a479964d8a720937503/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java#L262), the future would be completed already, and the cancellation of the future would result in false. Update the total request duration to 32500ms now, it is still not bullet proof but we would have much less chance to run into flaky tests now. fixes: #2669
1 parent 0cddadb commit e73740d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ void testCancelGetAttempt(boolean withCustomRetrySettings) throws Exception {
195195
setUp(withCustomRetrySettings);
196196
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
197197
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
198-
final int maxRetries = 100;
198+
final int maxRetries = 20;
199199

200200
FailingCallable callable = new FailingCallable(maxRetries - 1, "request", "SUCCESS", tracer);
201201
RetrySettings retrySettings =
202202
FAST_RETRY_SETTINGS
203203
.toBuilder()
204-
.setTotalTimeoutDuration(java.time.Duration.ofMillis(1000L))
204+
.setTotalTimeoutDuration(java.time.Duration.ofMillis(5000L))
205205
.setMaxAttempts(maxRetries)
206206
.build();
207207

@@ -259,10 +259,11 @@ void testCancelOuterFutureAfterStart() throws Exception {
259259
.toBuilder()
260260
// These params were selected to ensure that future tries to run and fail (at least
261261
// 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
262+
// it would take 2500 + 10000 + 10000 + 10000 = 32500ms for the future to complete,
263+
// which should
263264
// be more than enough time to cancel the future.
264-
.setInitialRetryDelayDuration(java.time.Duration.ofMillis(25L))
265-
.setMaxRetryDelayDuration(java.time.Duration.ofMillis(1000L))
265+
.setInitialRetryDelayDuration(java.time.Duration.ofMillis(2500L))
266+
.setMaxRetryDelayDuration(java.time.Duration.ofMillis(10000L))
266267
.setRetryDelayMultiplier(4.0)
267268
.setTotalTimeoutDuration(java.time.Duration.ofMillis(60000L))
268269
// Set this test to not use jitter as the randomized retry delay (RRD) may introduce

0 commit comments

Comments
 (0)
Please sign in to comment.