ykisana opened a new pull request, #20526:
URL: https://github.com/apache/druid/pull/20526
Fixes #20503.
### Description
`ScheduledExecutorsTest.testscheduleWithFixedDelay` asserted that the first
task starts strictly more than 100ms after scheduling (`firstTaskStart > 100`).
The test measured with `System.currentTimeMillis()`, but
`ScheduledThreadPoolExecutor` schedules on `System.nanoTime()` and can fire
exactly on time. A real gap of 100.0–100.99ms truncates to `100` ms, so the
strict bound failed even though the executor behaved correctly (CI: `was: 100`
on all 4 surefire attempts).
#### Fixed the flaky lower bound
- Record task start times with `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.
- Make the lower bound inclusive (`firstTaskStart >= 100`). `schedule()` is
called after the start time is recorded, so the measured gap can never be less
than the initial delay.
- Replace the comment that claimed the delay is always greater than 100ms
"due to overhead", which was the incorrect assumption behind the flake.
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.
<hr>
##### Key changed/added classes in this PR
* `ScheduledExecutorsTest`
<hr>
This PR has:
- [x] been self-reviewed.
- [x] added comments explaining the "why" and the intent of the code
wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths,
ensuring the threshold for [code
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
is met.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]