Repository navigation
test: fix flaky ScheduledExecutorsTest.testscheduleWithFixedDelay - #20526
Merged
FrankChen021 merged 2 commits intoOct 9, 2026
Merged
FrankChen021 merged 2 commits into
FrankChen021 merged 2 commits into
Conversation
FrankChen021
self-requested a review
October 9, 2026 02:06
FrankChen021
approved these changes
Oct 9, 2026
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20503.
Description
ScheduledExecutorsTest.testscheduleWithFixedDelayasserted that the first task starts strictly more than 100ms after scheduling (firstTaskStart > 100). The test measured withSystem.currentTimeMillis(), butScheduledThreadPoolExecutorschedules onSystem.nanoTime()and can fire exactly on time. A real gap of 100.0–100.99ms truncates to100ms, so the strict bound failed even though the executor behaved correctly (CI:was: 100on all 4 surefire attempts).Fixed the flaky lower bound
System.nanoTime(), relative to the start of the test, so the test uses the same monotonic clock as the executor and isn't affected by wall-clock adjustments.firstTaskStart >= 100).schedule()is called after the start time is recorded, so the measured gap can never be less than the initial delay.The checks on the delay between later tasks are unchanged. Every start time is measured from the same origin, so the gaps between them are the same as before.
Key changed/added classes in this PR
ScheduledExecutorsTestThis PR has: