Skip to content

Commit b5824c4

Browse files
committed
wip: add more tests
1 parent 4beae68 commit b5824c4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Sources/AsyncObjects/TaskOperation.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ public final class TaskOperation<R: Sendable>: Operation, AsyncObject, Loggable,
273273
) async throws {
274274
let key = UUID()
275275
log("Waiting", id: key, file: file, function: function, line: line)
276-
for await _ in event { break }
276+
var iter = event.makeAsyncIterator()
277+
await iter.next()
278+
277279
do {
278280
try Task.checkCancellation()
279281
} catch {
@@ -283,10 +285,11 @@ public final class TaskOperation<R: Sendable>: Operation, AsyncObject, Loggable,
283285
)
284286
throw error
285287
}
286-
do {
287-
let _ = try await execTask?.value
288+
289+
switch await self.result {
290+
case .success:
288291
log("Finished", id: key, file: file, function: function, line: line)
289-
} catch {
292+
case .failure(let error):
290293
log(
291294
"Finished with error: \(error)", id: key,
292295
file: file, function: function, line: line

Tests/AsyncObjectsTests/TaskOperationTests.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ class TaskOperationTests: XCTestCase {
7474
try await operation.wait(forSeconds: 3)
7575
}
7676

77-
func testFinisheAsyncdWait() async throws {
78-
let operation = TaskOperation { /* Do nothing */ }
77+
func testAsyncWaitError() async throws {
78+
let operation = TaskOperation { throw CancellationError() }
7979
operation.signal()
80-
try await operation.wait(forSeconds: 3)
80+
do {
81+
try await operation.wait(forSeconds: 3)
82+
XCTFail("Unexpected task progression")
83+
} catch is CancellationError {}
8184
}
8285

8386
func testDeinit() async throws {
@@ -265,6 +268,10 @@ class TaskOperationTaskManagementTests: XCTestCase {
265268
XCTAssertFalse(error.localizedDescription.isEmpty)
266269
default: XCTFail("Unexpected operation result")
267270
}
271+
do {
272+
try await operation.wait(forSeconds: 3)
273+
XCTFail("Unexpected task progression")
274+
} catch is DurationTimeoutError {}
268275
}
269276

270277
func testNotStartedCancellationError() async throws {
@@ -278,6 +285,10 @@ class TaskOperationTaskManagementTests: XCTestCase {
278285
XCTAssertFalse(error.localizedDescription.isEmpty)
279286
default: XCTFail("Unexpected operation result")
280287
}
288+
do {
289+
try await operation.wait(forSeconds: 3)
290+
XCTFail("Unexpected task progression")
291+
} catch is CancellationError {}
281292
}
282293
}
283294

0 commit comments

Comments
 (0)