Skip to content

Commit 25e05b6

Browse files
committed
test(gax): isolate local executors inside loops in ScheduledRetryingExecutorTest
Addressed PR comments by moving the creation and shutdown of local executors inside the test loops for testSuccessWithFailuresPeekAttempt and testCancelOuterFutureAfterStart to ensure complete isolation between iterations and avoid potential flakiness. TAG=agy CONV=71af906a-b7dc-4dda-a2fa-ebe24b5d8b91 BUG=13535
1 parent 31354b4 commit 25e05b6

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ void testSuccessWithFailuresPeekAttempt() throws Exception {
103103
.setTotalTimeoutDuration(java.time.Duration.ofMillis(10000L))
104104
.setMaxAttempts(100)
105105
.build();
106-
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
107-
try {
108-
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
109-
106+
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
107+
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
108+
try {
110109
FailingCallable callable = new FailingCallable(15, "request", "SUCCESS", tracer);
111110

112111
RetryingExecutorWithContext<String> executor =
@@ -151,9 +150,9 @@ void testSuccessWithFailuresPeekAttempt() throws Exception {
151150
assertFutureSuccess(future);
152151
assertEquals(15, future.getAttemptSettings().getAttemptCount());
153152
assertTrue(failedAttempts.get() > 0);
153+
} finally {
154+
localExecutor.shutdownNow();
154155
}
155-
} finally {
156-
localExecutor.shutdownNow();
157156
}
158157
}
159158

@@ -284,9 +283,9 @@ void testCancelOuterFutureAfterStart() throws Exception {
284283
// tiny RRD value is small, but not impossible.
285284
.setJittered(false)
286285
.build();
287-
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
288-
try {
289-
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
286+
for (int executionsCount = 0; executionsCount < EXECUTIONS_COUNT; executionsCount++) {
287+
ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
288+
try {
290289
FailingCallable callable = new FailingCallable(4, "request", "SUCCESS", tracer);
291290
RetryingExecutorWithContext<String> executor =
292291
getRetryingExecutor(
@@ -317,9 +316,9 @@ void testCancelOuterFutureAfterStart() throws Exception {
317316
// i.e. The future from executor.submit() has been run by the ScheduledExecutor
318317
assertTrue(future.getAttemptSettings().getAttemptCount() > 0);
319318
assertTrue(future.getAttemptSettings().getAttemptCount() < 4);
319+
} finally {
320+
localExecutor.shutdownNow();
320321
}
321-
} finally {
322-
localExecutor.shutdownNow();
323322
}
324323
}
325324

0 commit comments

Comments
 (0)