What is the expected behavior here:
func testChildTaskCancellation() async throws {
let t = Task {
await Task.yield()
XCTAssertTrue(Task.isCancelled)
let child = Task {
await Task.yield()
XCTAssertTrue(Task.isCancelled) // Failure here
try Task.checkCancellation()
}
print("-- child.isCancelled: \(child.isCancelled)") // This prints "true"
XCTAssertTrue(child.isCancelled) // This assert passes
_ = try await child.value
XCTAssertTrue(Task.isCancelled)
}
t.cancel()
try? await t.value
}
A child task is created after the parent is cancelled. I had expected the child task to be created but in a cancelled state. The expectation and failure is noted in the code. Is this a bug or are my expectations incorrect? The fact that the child
reports isCancelled
as true
leads me to believe my expectations are correct.