Fix flakey testScheduledCallbackNotExecutedBeforeDeadline (#3550)

### 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.
This commit is contained in:
Rick Newton-Rogers authored and GitHub committed 2026-03-16 11:36:02 +00:00
1 parent b9d20d3476
commit e313684789
1 file changed
+3 -1
@@ -241,7 +241,9 @@ extension _BaseScheduledCallbackTests {
func testScheduledCallbackNotExecutedBeforeDeadline() async throws {
let handler = MockScheduledCallbackHandler()
_ = try self.loop.scheduleCallback(in: .milliseconds(1), handler: handler)
// Use a long deadline so that even if the short sleep overshoots on a loaded CI machine,
// it cannot reach the callback deadline.
_ = try self.loop.scheduleCallback(in: .hours(1), handler: handler)
handler.assert(callbackCount: 0, cancelCount: 0)
try await self.advanceTime(by: .microseconds(1))