Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,16 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
func testTasksScheduledDuringShutdownAreAutomaticallyCancelled() async throws {
let eventLoop = NIOAsyncTestingEventLoop()
let tasksRun = ManagedAtomic(0)
var childTasks: [Scheduled<Void>] = []

func scheduleRecursiveTask(
at taskStartTime: NIODeadline,
andChildTaskAfter childTaskStartDelay: TimeAmount
) -> Scheduled<Void> {
eventLoop.scheduleTask(deadline: taskStartTime) {
tasksRun.wrappingIncrement(ordering: .relaxed)
childTasks.append(
scheduleRecursiveTask(
at: eventLoop.now + childTaskStartDelay,
andChildTaskAfter: childTaskStartDelay
)
tasksRun.wrappingIncrement(ordering: .releasing)
_ = scheduleRecursiveTask(
at: eventLoop.now + childTaskStartDelay,
andChildTaskAfter: childTaskStartDelay
)
}
}
Expand All @@ -502,17 +499,15 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {

try await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
try await Task.sleep(nanoseconds: 1_000_000)
try await Task.sleep(nanoseconds: 10_000_000)
await eventLoop.shutdownGracefully()
}
group.addTask {
await eventLoop.advanceTime(to: .uptimeNanoseconds(1))
}

await eventLoop.advanceTime(to: .uptimeNanoseconds(1))
try await group.waitForAll()
}

XCTAssertGreaterThan(tasksRun.load(ordering: .relaxed), 1)
XCTAssertEqual(childTasks.count, tasksRun.load(ordering: .relaxed))
XCTAssertGreaterThan(tasksRun.load(ordering: .acquiring), 1)
}

func testShutdownCancelsRemainingScheduledTasks() async {
Expand Down
Loading