Skip to content

Fix flakey scheduled callback cancellation tests on iOS simulator#3556

Merged
rnro merged 1 commit intoapple:mainfrom
rnro:short_timers_in_tests
Mar 20, 2026
Merged

Fix flakey scheduled callback cancellation tests on iOS simulator#3556
rnro merged 1 commit intoapple:mainfrom
rnro:short_timers_in_tests

Conversation

@rnro
Copy link
Copy Markdown
Contributor

@rnro rnro commented Mar 19, 2026

Motivation

  • MTELGScheduledCallbackTests.testCancelAfterShutdownDoesNotCallCancellationCallbackAgain is failing on iOS simulator CI. It schedules a callback with a .milliseconds(1) deadline, then shuts down, expecting shutdown to cancel the callback. On the simulator the 1ms timer fires before shutdown processes, so the callback executes instead of being cancelled.
  • This is the same class of bug previously fixed for testScheduledCallbackNotExecutedBeforeDeadline in dcecf0c.

Modifications

  • Change the scheduled callback deadline from .milliseconds(1) to .hours(1) in testCancelAfterShutdownDoesNotCallCancellationCallbackAgain (the observed failure).
  • Speculatively apply the same fix to testCancelExecutesCancellationCallback, testCancelAfterCancelDoesNotCallCancellationCallbackAgain, and testShutdownDoesNotCancelCancelledCallbacksAgain which have the same pattern.
  • The EmbeddedEventLoop and NIOAsyncTestingEventLoop subclasses use virtual time so this does not extend test duration.

Result

  • Scheduled callback cancellation tests no longer depend on real-time precision and should not flake on slow CI runners or simulators.

Motivation

* `MTELGScheduledCallbackTests.testCancelAfterShutdownDoesNotCallCancellationCallbackAgain`
  is failing on iOS simulator CI. It schedules a callback with a `.milliseconds(1)`
  deadline, then shuts down, expecting shutdown to cancel the callback. On the
  simulator the 1ms timer fires before shutdown processes, so the callback executes
  instead of being cancelled.
* This is the same class of bug previously fixed for
  `testScheduledCallbackNotExecutedBeforeDeadline` in dcecf0c.

Modifications

* Change the scheduled callback deadline from `.milliseconds(1)` to `.hours(1)` in
  `testCancelAfterShutdownDoesNotCallCancellationCallbackAgain` (the observed failure).
* Speculatively apply the same fix to `testCancelExecutesCancellationCallback`,
  `testCancelAfterCancelDoesNotCallCancellationCallbackAgain`, and
  `testShutdownDoesNotCancelCancelledCallbacksAgain` which have the same pattern.
* The `EmbeddedEventLoop` and `NIOAsyncTestingEventLoop` subclasses use virtual time
  so this does not extend test duration.

Result

* Scheduled callback cancellation tests no longer depend on real-time precision and
  should not flake on slow CI runners or simulators.
@rnro rnro added the semver/none No version bump required. label Mar 19, 2026
@rnro rnro merged commit 66c50a7 into apple:main Mar 20, 2026
52 of 54 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