mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
remove XCTest expectations with timeouts (#1539)
Motivation: The XCTest expectations caused problems when they time out. When they time out, the execution continues which in the tests in question then shut down the EventLoop. Shutting down the event loop meant that other things don't happen which caused the test to hang. The XCTest expectations however tell us about the failure at the end of the test (which we never reach). Modifications: Remove the XCTest expectations with timeouts. Result: Even slow CI should pass this test correctly. Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
1 parent
8b05ba64b1
commit
def2f0efe9
1 file changed
+17
-17
@@ -143,9 +143,10 @@ public final class EventLoopTest : XCTestCase {
|
||||
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
|
||||
}
|
||||
|
||||
let expect = expectation(description: "Is cancelling RepatedTask")
|
||||
let counter = NIOAtomic<Int>.makeAtomic(value: 0)
|
||||
let loop = eventLoopGroup.next()
|
||||
let allDone = DispatchGroup()
|
||||
allDone.enter()
|
||||
loop.scheduleRepeatedTask(initialDelay: initialDelay, delay: delay) { repeatedTask -> Void in
|
||||
XCTAssertTrue(loop.inEventLoop)
|
||||
let initialValue = counter.load()
|
||||
@@ -153,16 +154,15 @@ public final class EventLoopTest : XCTestCase {
|
||||
if initialValue == 0 {
|
||||
XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay)
|
||||
} else if initialValue == count {
|
||||
expect.fulfill()
|
||||
repeatedTask.cancel()
|
||||
allDone.leave()
|
||||
}
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 1) { error in
|
||||
XCTAssertNil(error)
|
||||
XCTAssertEqual(counter.load(), count + 1)
|
||||
XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay + Int64(count) * delay)
|
||||
}
|
||||
allDone.wait()
|
||||
|
||||
XCTAssertEqual(counter.load(), count + 1)
|
||||
XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay + Int64(count) * delay)
|
||||
}
|
||||
|
||||
public func testScheduledTaskThatIsImmediatelyCancelledNeverFires() throws {
|
||||
@@ -226,10 +226,11 @@ public final class EventLoopTest : XCTestCase {
|
||||
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
|
||||
}
|
||||
|
||||
let expect = expectation(description: "Is cancelling RepatedTask")
|
||||
let group = DispatchGroup()
|
||||
let hasFiredGroup = DispatchGroup()
|
||||
let isCancelledGroup = DispatchGroup()
|
||||
let loop = eventLoopGroup.next()
|
||||
group.enter()
|
||||
hasFiredGroup.enter()
|
||||
isCancelledGroup.enter()
|
||||
var isAllowedToFire = true // read/write only on `loop`
|
||||
var hasFired = false // read/write only on `loop`
|
||||
let repeatedTask = loop.scheduleRepeatedTask(initialDelay: initialDelay, delay: delay) { (_: RepeatedTask) -> Void in
|
||||
@@ -238,23 +239,22 @@ public final class EventLoopTest : XCTestCase {
|
||||
// we can only do this once as we can only leave the DispatchGroup once but we might lose a race and
|
||||
// the timer might fire more than once (until `shouldNoLongerFire` becomes true).
|
||||
hasFired = true
|
||||
group.leave()
|
||||
expect.fulfill()
|
||||
hasFiredGroup.leave()
|
||||
}
|
||||
XCTAssertTrue(isAllowedToFire)
|
||||
}
|
||||
group.notify(queue: DispatchQueue.global()) {
|
||||
hasFiredGroup.notify(queue: DispatchQueue.global()) {
|
||||
repeatedTask.cancel()
|
||||
loop.execute {
|
||||
// only now do we know that the `cancel` must have gone through
|
||||
isAllowedToFire = false
|
||||
isCancelledGroup.leave()
|
||||
}
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 1) { error in
|
||||
XCTAssertNil(error)
|
||||
XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay)
|
||||
}
|
||||
hasFiredGroup.wait()
|
||||
XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay)
|
||||
isCancelledGroup.wait()
|
||||
}
|
||||
|
||||
public func testScheduleRepeatedTaskToNotRetainRepeatedTask() throws {
|
||||
|
||||
Reference in new issue
Block a user