Skip to content

Fix flakey testScheduledCallbackNotExecutedBeforeDeadline#3550

Merged
rnro merged 2 commits intoapple:mainfrom
rnro:testScheduledCallbackNotExecutedBeforeDeadline
Mar 16, 2026
Merged

Fix flakey testScheduledCallbackNotExecutedBeforeDeadline#3550
rnro merged 2 commits intoapple:mainfrom
rnro:testScheduledCallbackNotExecutedBeforeDeadline

Conversation

@rnro
Copy link
Copy Markdown
Contributor

@rnro rnro commented Mar 16, 2026

Motivation

  • MTELGScheduledCallbackTests.testScheduledCallbackNotExecutedBeforeDeadline is flakey on macOS CI. It schedules a callback with a 1ms deadline, sleeps for 1µs via Task.sleep, then asserts the callback hasn't fired. On a loaded CI runner, Task.sleep can overshoot well past 1ms, causing the callback to fire before the assertion.

Modifications

  • Increase the scheduled callback deadline from .milliseconds(1) to .hours(1) in _BaseScheduledCallbackTests. This makes it impossible for the short sleep to overshoot past the deadline. The EmbeddedEventLoop and NIOAsyncTestingEventLoop subclasses use virtual time so this change is harmless to them.

Result

  • The test reliably asserts that a callback is not executed before its deadline without depending on real-time sleep precision.

Motivation

* `MTELGScheduledCallbackTests.testScheduledCallbackNotExecutedBeforeDeadline` is
  flakey on macOS CI. It schedules a callback with a 1ms deadline, sleeps for 1µs
  via `Task.sleep`, then asserts the callback hasn't fired. On a loaded CI runner,
  `Task.sleep` can overshoot well past 1ms, causing the callback to fire before
  the assertion.

Modifications

* Increase the scheduled callback deadline from `.milliseconds(1)` to `.hours(1)`
  in `_BaseScheduledCallbackTests`. This makes it impossible for the short sleep
  to overshoot past the deadline. The `EmbeddedEventLoop` and
  `NIOAsyncTestingEventLoop` subclasses use virtual time so this change is
  harmless to them.

Result

* The test reliably asserts that a callback is not executed before its deadline
  without depending on real-time sleep precision.
@rnro rnro added the semver/none No version bump required. label Mar 16, 2026
@rnro rnro marked this pull request as ready for review March 16, 2026 11:26
@rnro rnro enabled auto-merge (squash) March 16, 2026 11:28
@rnro rnro merged commit e313684 into apple:main Mar 16, 2026
51 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants