Skip to content

test(gax): use FakeApiClock and RecordingScheduler in ScheduledRetryingExecutorTest - #14706

Merged
lqiu96 merged 6 commits into
googleapis:mainfrom
lqiu96:fix/gax-scheduled-retrying-executor-fake-clock-13535
Oct 23, 2026
Merged

lqiu96 merged 6 commits into
googleapis:mainfrom
lqiu96:fix/gax-scheduled-retrying-executor-fake-clock-13535

Conversation

@lqiu96

@lqiu96 lqiu96 commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #13535

…read.sleep

Replace CurrentMillisClock and real Thread.sleep delays in
DirectRetryingExecutorTest with FakeApiClock and a sleep() override
that advances virtual time deterministically. This prevents
testMaxRetriesExceeded from flaking with premature totalTimeout
expiration on slow CI runners.

Fixes googleapis#14625
…elpers

Use FakeApiClock and RecordingScheduler in ScheduledRetryingExecutorTest
for deterministic, sleep-free retry tests without modifying existing
asynchronous in-flight test methods.
Refactor RecordingScheduler to extend ScheduledThreadPoolExecutor
directly, eliminating Mockito dependencies and strict-stubbing friction.
Add Javadoc documentation for FakeApiClock and RecordingScheduler.

Fixes googleapis#13535

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the retrying executor tests to use deterministic simulated time instead of real wall-clock sleeps, replacing the Mockito-based RecordingScheduler with a concrete ScheduledThreadPoolExecutor that advances a FakeApiClock. DirectRetryingExecutorTest and ScheduledRetryingExecutorTest are updated to use this fake clock. The feedback suggests replacing the non-thread-safe ArrayList used for sleepDurations in RecordingScheduler with a CopyOnWriteArrayList to prevent potential concurrent modification issues during multi-threaded test execution.

@lqiu96
lqiu96 requested a review from blakeli0 October 23, 2026 15:16
@lqiu96

lqiu96 commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors RecordingScheduler from a Mockito-mocked ScheduledExecutorService to a concrete class extending ScheduledThreadPoolExecutor. This allows scheduled tasks to execute asynchronously with zero delay while advancing a FakeApiClock, eliminating real-time backoff sleeps in tests. Additionally, ScheduledRetryingExecutorTest is updated to utilize this new scheduler. The feedback recommends also overriding the Callable overload of schedule in RecordingScheduler to prevent potential test hangs or real-time delays if the underlying executor is updated to schedule Callable tasks in the future.

@lqiu96
lqiu96 marked this pull request as ready for review October 23, 2026 16:06
@lqiu96
lqiu96 requested a review from a team as a code owner October 23, 2026 16:06
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 23, 2026
@lqiu96
lqiu96 enabled auto-merge (squash) October 23, 2026 20:00
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 23, 2026
@lqiu96
lqiu96 merged commit ecd27c5 into googleapis:main Oct 23, 2026
290 of 299 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test ScheduledRetryingExecutorTest.testSuccessWithFailuresGetAttempt

3 participants