Skip to content

Flaky test: NIOPOSIXTests.EventLoopTest.testCancelledScheduledTasksDoNotHoldOnToRunClosure() #2239

Open
@dnadoba

Description

@dnadoba

I have seen it fail in CI and locally a couple of times now. It is also reliably reproducible if run repeatedly after ~500-2000 iterations.

func testCancelledScheduledTasksDoNotHoldOnToRunClosure() {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
class Thing {}
weak var weakThing: Thing? = nil
func make() -> Scheduled<Never> {
let aThing = Thing()
weakThing = aThing
return group.next().scheduleTask(in: .hours(1)) {
preconditionFailure("this should definitely not run: \(aThing)")
}
}
let scheduled = make()
scheduled.cancel()
assert(weakThing == nil, within: .seconds(1))
XCTAssertThrowsError(try scheduled.futureResult.wait()) { error in
XCTAssertEqual(EventLoopError.cancelled, error as? EventLoopError)
}
}

I have played a bit around with the time and testInterval but this doesn't seem to really help make this test reliable.
The memory debugger shows that an instance to weakThing is still hold by the EventLoop which it should not.
Screenshot 2022-08-08 at 15 21 25
Needs further investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions