Skip to content

Commit 933083a

Browse files
committed
Fix priority test
Priorities keep shifting since I first wrote this and are apparently different on different OS's and different versions of the same OS. Since the test is checking that entering and exiting tasks doesn't effect the outer-scoped priority, I've set a variable based on the main thread's priories, which should be inherited by the child.
1 parent fc46c00 commit 933083a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

test/Concurrency/Runtime/async_task_priority_current.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ extension TaskPriority: CustomStringConvertible {
1717
}
1818
}
1919

20+
@available(SwiftStdlib 5.5, *)
21+
@main struct Main {
22+
static func main() async {
23+
print("main priority: \(Task.currentPriority)") // CHECK: main priority: TaskPriority(rawValue: [[#MAIN_PRIORITY:]])
24+
await test_detach()
25+
await test_multiple_lo_indirectly_escalated()
26+
}
27+
}
28+
2029
@available(SwiftStdlib 5.5, *)
2130
func test_detach() async {
2231
let a1 = Task.currentPriority
23-
print("a1: \(a1)") // CHECK: TaskPriority(rawValue: 25)
32+
print("a1: \(a1)") // CHECK: a1: TaskPriority(rawValue: [[#MAIN_PRIORITY]])
2433

2534
// Note: remember to detach using a higher priority, otherwise a lower one
2635
// might be escalated by the get() and we could see `default` in the detached
@@ -30,8 +39,15 @@ func test_detach() async {
3039
print("a2: \(a2)") // CHECK: a2: TaskPriority(rawValue: 25)
3140
}.get()
3241

33-
let a3 = Task.currentPriority
34-
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: 25)
42+
await detach(priority: .default) {
43+
let a3 = Task.currentPriority
44+
// The priority of 'a3' may either be 21 (default) or elevated to that of
45+
// the main function, whichever is greater.
46+
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: [[#max(MAIN_PRIORITY,21)]]
47+
}.get()
48+
49+
let a4 = Task.currentPriority
50+
print("a4: \(a4)") // CHECK: a4: TaskPriority(rawValue: [[#MAIN_PRIORITY]])
3551
}
3652

3753
@available(SwiftStdlib 5.5, *)
@@ -66,10 +82,4 @@ func test_multiple_lo_indirectly_escalated() async {
6682
print("default done") // CHECK: default done
6783
}
6884

69-
@available(SwiftStdlib 5.5, *)
70-
@main struct Main {
71-
static func main() async {
72-
await test_detach()
73-
await test_multiple_lo_indirectly_escalated()
74-
}
75-
}
85+

0 commit comments

Comments
 (0)