Skip to content

Commit dd3c72c

Browse files
committed
Update
1 parent f55c38d commit dd3c72c

File tree

5 files changed

+54
-51
lines changed

5 files changed

+54
-51
lines changed

Sources/ConcurrencyTaskManager/TaskManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public final class TaskManager: Sendable {
179179
let extendedContinuation: AutoReleaseContinuationBox<Return> = .init(nil)
180180

181181
let referenceTask = Task { [weak extendedContinuation] in
182-
return try await withUnsafeThrowingContinuation{ (continuation: UnsafeContinuation<Return, Error>) in
182+
return try await withUnsafeThrowingContinuation { (continuation: UnsafeContinuation<Return, Error>) in
183183
extendedContinuation?.setContinuation(continuation)
184184
}
185185
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import ConcurrencyTaskManager
2-
import XCTest
2+
import Testing
33

4-
final class SimpleTest: XCTestCase {
4+
@Suite struct SimpleTest {
55

6-
func test_simple_task() async {
6+
@Test func simpleTask() async {
77
let manager = TaskManager()
88

99
let completed = UnfairLockAtomic<Bool>(false)
@@ -14,6 +14,6 @@ final class SimpleTest: XCTestCase {
1414

1515
_ = try? await task.value
1616

17-
XCTAssertTrue(completed.value)
17+
#expect(completed.value)
1818
}
1919
}

Tests/ConcurrencyTaskManagerTests/TaskKeyTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import XCTest
1+
import Testing
22
import ConcurrencyTaskManager
33

4-
final class TaskKeyTests: XCTestCase {
4+
@Suite struct TaskKeyTests {
55

6-
func testBase() {
6+
@Test func base() {
77

88
enum LocalKey: TaskKeyType {}
99
enum LocalKey2: TaskKeyType {}
1010

1111
let key = TaskKey(LocalKey.self)
1212
let key2 = TaskKey(LocalKey2.self)
1313

14-
XCTAssertNotEqual(key, key2)
15-
XCTAssertEqual(key, key)
14+
#expect(key != key2)
15+
#expect(key == key)
1616
}
1717

18-
func testCombined() {
18+
@Test func combined() {
1919

2020
enum LocalKey: TaskKeyType {}
2121

2222
let key = TaskKey(LocalKey.self)
2323

24-
XCTAssertEqual(key, key.combined(.init(LocalKey.self)))
25-
XCTAssertNotEqual(key, key.combined("A"))
24+
#expect(key == key.combined(.init(LocalKey.self)))
25+
#expect(key != key.combined("A"))
2626

2727
}
2828

Tests/ConcurrencyTaskManagerTests/TaskManagerTests.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import ConcurrencyTaskManager
2-
import XCTest
2+
import Testing
33

44
@discardableResult
55
func dummyTask<V>(_ v: V, nanoseconds: UInt64) async -> V {
66
try? await Task.sleep(nanoseconds: nanoseconds)
77
return v
88
}
99

10-
final class TaskManagerTests: XCTestCase {
10+
@Suite struct TaskManagerTests {
1111

12-
func test_run_distinct_tasks() async {
12+
@Test func runDistinctTasks() async {
1313

1414
let manager = TaskManager()
1515

@@ -30,11 +30,11 @@ final class TaskManagerTests: XCTestCase {
3030

3131
try? await Task.sleep(nanoseconds: 1_000_000)
3232

33-
XCTAssertEqual(Set(events.value), Set(["1", "2", "3"]))
33+
#expect(Set(events.value) == Set(["1", "2", "3"]))
3434

3535
}
3636

37-
func test_drop_current_task_in_key() async {
37+
@Test func dropCurrentTaskInKey() async {
3838

3939
let manager = TaskManager()
4040

@@ -51,10 +51,10 @@ final class TaskManagerTests: XCTestCase {
5151

5252
try? await Task.sleep(nanoseconds: 2_000_000_000)
5353

54-
XCTAssertEqual(events.value, ["9"])
54+
#expect(events.value == ["9"])
5555
}
5656

57-
func test_wait_current_task_in_key() async {
57+
@Test func waitCurrentTaskInKey() async {
5858

5959
let manager = TaskManager()
6060

@@ -76,10 +76,10 @@ final class TaskManagerTests: XCTestCase {
7676

7777
try? await Task.sleep(nanoseconds: 1_000_000_000)
7878

79-
XCTAssertEqual(events.value, ["1", "2"])
79+
#expect(events.value == ["1", "2"])
8080
}
8181

82-
func test_isRunning() async {
82+
@Test func isRunning() async {
8383

8484
let manager = TaskManager()
8585

@@ -90,13 +90,13 @@ final class TaskManagerTests: XCTestCase {
9090
_ = manager.task(key: .init("request"), mode: .waitInCurrent) {
9191
print("done 1")
9292
callCount.modify { $0 += 1 }
93-
XCTAssert(_isRunning.value == true)
93+
#expect(_isRunning.value == true)
9494
}
9595

9696
_ = manager.task(key: .init("request"), mode: .waitInCurrent) {
9797
print("done 2")
9898
callCount.modify { $0 += 1 }
99-
XCTAssert(_isRunning.value == true)
99+
#expect(_isRunning.value == true)
100100
}
101101

102102
try? await Task.sleep(nanoseconds: 1_000_000_000)
@@ -106,10 +106,10 @@ final class TaskManagerTests: XCTestCase {
106106

107107
try? await Task.sleep(nanoseconds: 1_000_000_000)
108108

109-
XCTAssertEqual(callCount.value, 2)
109+
#expect(callCount.value == 2)
110110
}
111111

112-
func test_cancel_specific_key() async {
112+
@Test func cancelSpecificKey() async {
113113
let manager = TaskManager()
114114

115115
let events: UnfairLockAtomic<[String]> = .init([])
@@ -143,10 +143,10 @@ final class TaskManagerTests: XCTestCase {
143143
try? await Task.sleep(nanoseconds: 2_000_000_000)
144144

145145
// key1 and key3 should complete, key2 should be cancelled
146-
XCTAssertEqual(Set(events.value), Set(["key1", "key3"]))
146+
#expect(Set(events.value) == Set(["key1", "key3"]))
147147
}
148148

149-
func test_cancel_key_with_multiple_queued_tasks() async {
149+
@Test func cancelKeyWithMultipleQueuedTasks() async {
150150
let manager = TaskManager()
151151

152152
let events: UnfairLockAtomic<[String]> = .init([])
@@ -180,22 +180,24 @@ final class TaskManagerTests: XCTestCase {
180180
try? await Task.sleep(nanoseconds: 2_000_000_000)
181181

182182
// No tasks should have completed
183-
XCTAssertEqual(events.value, [])
183+
#expect(events.value == [])
184184
}
185185

186-
func test_cancel_nonexistent_key() async {
186+
@Test func cancelNonexistentKey() async {
187187
let manager = TaskManager()
188188

189189
// This should not crash
190190
manager.cancel(key: .init("nonexistent"))
191191

192192
// Verify manager still works after cancelling nonexistent key
193-
let expectation = XCTestExpectation(description: "Task completes")
193+
let completed = UnfairLockAtomic<Bool>(false)
194194

195195
manager.task(key: .init("test"), mode: .dropCurrent) {
196-
expectation.fulfill()
196+
completed.modify { $0 = true }
197197
}
198198

199-
await fulfillment(of: [expectation], timeout: 1.0)
199+
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
200+
201+
#expect(completed.value)
200202
}
201203
}

Tests/ConcurrencyTaskManagerTests/TaskWaitTests.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import ConcurrencyTaskManager
2-
import XCTest
2+
import Testing
3+
import Foundation
34

45
/// Tests for TaskNode wait functionality via TaskManager
5-
final class TaskWaitTests: XCTestCase {
6+
@Suite struct TaskWaitTests {
67

7-
func test_wait_for_queued_tasks() async throws {
8+
@Test func waitForQueuedTasks() async throws {
89
let manager = TaskManager()
910
let events = UnfairLockAtomic<[String]>([])
1011

@@ -30,10 +31,10 @@ final class TaskWaitTests: XCTestCase {
3031
_ = try await task3.value
3132

3233
// Tasks should execute in order
33-
XCTAssertEqual(events.value, ["task1", "task2", "task3"])
34+
#expect(events.value == ["task1", "task2", "task3"])
3435
}
3536

36-
func test_drop_mode_cancels_previous_tasks() async throws {
37+
@Test func dropModeCancelsPreviousTasks() async throws {
3738
let manager = TaskManager()
3839
let events = UnfairLockAtomic<[String]>([])
3940

@@ -55,18 +56,18 @@ final class TaskWaitTests: XCTestCase {
5556
// Wait for tasks
5657
do {
5758
_ = try await task1.value
58-
XCTFail("Task1 should have been cancelled")
59+
Issue.record("Task1 should have been cancelled")
5960
} catch is CancellationError {
6061
// Expected
6162
}
6263

6364
_ = try await task2.value
6465

6566
// Only task2 should complete
66-
XCTAssertEqual(events.value, ["task2"])
67+
#expect(events.value == ["task2"])
6768
}
6869

69-
func test_concurrent_tasks_with_different_keys() async throws {
70+
@Test func concurrentTasksWithDifferentKeys() async throws {
7071
let manager = TaskManager()
7172
let events = UnfairLockAtomic<[String]>([])
7273
let startTime = Date()
@@ -95,11 +96,11 @@ final class TaskWaitTests: XCTestCase {
9596
let elapsed = Date().timeIntervalSince(startTime)
9697

9798
// Should complete in ~100ms (concurrent), not ~300ms (sequential)
98-
XCTAssertLessThan(elapsed, 0.2, "Tasks should run concurrently")
99-
XCTAssertEqual(events.value.count, 3, "All tasks should complete")
99+
#expect(elapsed < 0.2, "Tasks should run concurrently")
100+
#expect(events.value.count == 3, "All tasks should complete")
100101
}
101102

102-
func test_task_cancellation_propagation() async throws {
103+
@Test func taskCancellationPropagation() async throws {
103104
let manager = TaskManager()
104105
let events = UnfairLockAtomic<[String]>([])
105106

@@ -143,13 +144,13 @@ final class TaskWaitTests: XCTestCase {
143144
_ = try? await task3.value
144145

145146
// Should see cancellation events
146-
XCTAssertTrue(events.value.contains("task1-cancelled") || events.value.isEmpty)
147-
XCTAssertFalse(events.value.contains("task1-completed"))
148-
XCTAssertFalse(events.value.contains("task2-completed"))
149-
XCTAssertFalse(events.value.contains("task3-completed"))
147+
#expect(events.value.contains("task1-cancelled") || events.value.isEmpty)
148+
#expect(!events.value.contains("task1-completed"))
149+
#expect(!events.value.contains("task2-completed"))
150+
#expect(!events.value.contains("task3-completed"))
150151
}
151152

152-
func test_task_completion_order_with_wait_mode() async throws {
153+
@Test func taskCompletionOrderWithWaitMode() async throws {
153154
let manager = TaskManager()
154155
let events = UnfairLockAtomic<[String]>([])
155156
let completionTimes = UnfairLockAtomic<[String: Date]>([:])
@@ -181,12 +182,12 @@ final class TaskWaitTests: XCTestCase {
181182
_ = try await task3.value
182183

183184
// Verify order
184-
XCTAssertEqual(events.value, ["task1", "task2", "task3"], "Tasks should complete in order")
185+
#expect(events.value == ["task1", "task2", "task3"], "Tasks should complete in order")
185186

186187
// Verify timing - task2 should complete after task1 despite being faster
187188
if let time1 = completionTimes.value["task1"],
188189
let time2 = completionTimes.value["task2"] {
189-
XCTAssertTrue(time2 > time1, "Task2 should complete after task1")
190+
#expect(time2 > time1, "Task2 should complete after task1")
190191
}
191192
}
192193

0 commit comments

Comments
 (0)