forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncFirstResolvedTests.swift
More file actions
32 lines (29 loc) · 1.03 KB
/
Copy pathAsyncFirstResolvedTests.swift
File metadata and controls
32 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import XCTest
@testable import Omi_Computer
final class AsyncFirstResolvedTests: XCTestCase {
/// Regression: the dwell capture race must return when the fallback branch
/// resolves even if the primary branch NEVER completes — `withTaskGroup`
/// failed this (leaving the group awaits the stalled child).
func testResolvesWhenOneBranchNeverCompletes() async {
let result = await AsyncFirstResolved.run(
{ () async -> Int? in
await withCheckedContinuation { (_: CheckedContinuation<Void, Never>) in
// Never resumed: a stalled, cancellation-insensitive call.
}
return 1
},
{ () async -> Int? in nil }
)
XCTAssertNil(result, "the fallback branch must win against a hung primary")
}
func testFastPrimaryWins() async {
let result = await AsyncFirstResolved.run(
{ () async -> Int? in 42 },
{ () async -> Int? in
await withCheckedContinuation { (_: CheckedContinuation<Void, Never>) in }
return nil
}
)
XCTAssertEqual(result, 42)
}
}