mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Fix flakey testScheduledCallbackNotExecutedBeforeDeadline
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:
1 parent
b31565862a
commit
dcecf0cb68
1 file changed
+3
-1
@@ -241,7 +241,9 @@ extension _BaseScheduledCallbackTests {
|
|||||||
func testScheduledCallbackNotExecutedBeforeDeadline() async throws {
|
func testScheduledCallbackNotExecutedBeforeDeadline() async throws {
|
||||||
let handler = MockScheduledCallbackHandler()
|
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)
|
handler.assert(callbackCount: 0, cancelCount: 0)
|
||||||
|
|
||||||
try await self.advanceTime(by: .microseconds(1))
|
try await self.advanceTime(by: .microseconds(1))
|
||||||
|
|||||||
Reference in new issue
Block a user