TM-SGNL-iOS/SignalServiceKit/Concurrency/CancellableContinuationTest.swift
TeleMessage developers dde0620daf initial commit
2025-05-03 12:28:28 -07:00

28 lines
764 B
Swift

//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import XCTest
@testable import SignalServiceKit
final class CancellableContinuationTest: XCTestCase {
func testNestedCancellation() async throws {
let cancellableTask = Task {
let cancellableContinuation = CancellableContinuation<Void>()
try await withTaskCancellationHandler(
operation: cancellableContinuation.wait,
onCancel: { /* do nothing */ }
)
}
cancellableTask.cancel()
do {
try await cancellableTask.value
XCTFail("Task must fail.")
} catch is CancellationError {
// this is fine
}
}
}