11// RUN: %empty-directory(%t)
22
3- // RUN: %target-build-swift %s -Xfrontend -disable-availability-checking -parse-as-library -o %t/async_task_priority
4- // RUN: %target-codesign %t/async_task_priority
5- // RUN: %target-run %t/async_task_priority
3+ // RUN: %target-build-swift %s -Xfrontend -disable-availability-checking -parse-as-library -o %t/async_task_escalate_priority
4+ // RUN: %target-codesign %t/async_task_escalate_priority
5+ // RUN: %target-run %t/async_task_escalate_priority
66
77// REQUIRES: VENDOR=apple
88// REQUIRES: executable_test
2424
2525import Darwin
2626@preconcurrency import Dispatch
27- import StdlibUnittest
27+
28+ func expectEqual( _ l: TaskPriority , _ r: TaskPriority ,
29+ function: String = #function, file: String = #fileID, line: UInt = #line) {
30+ precondition ( l == r, " Priority [ \( l) ] did not equal \( r) @ \( file) : \( line) ( \( function) ) " )
31+ }
2832
2933func loopUntil( priority: TaskPriority ) async {
3034 var loops = 10
@@ -77,8 +81,7 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
7781
7882 let top_level = Task . detached { /* To detach from main actor when running work */
7983
80- let tests = TestSuite ( " Task Priority escalation " )
81- tests. test ( " Basic task_escalate when task is running " ) {
84+ func basicTask_escalateWhenTaskIsRunning( ) async {
8285 let sem1 = DispatchSemaphore ( value: 0 )
8386 let sem2 = DispatchSemaphore ( value: 0 )
8487 let task = Task ( priority: . background) {
@@ -97,8 +100,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
97100 Task . escalatePriority ( task, to: . default)
98101 sem2. wait ( )
99102 }
103+ await basicTask_escalateWhenTaskIsRunning ( )
100104
101- tests . test ( " Trigger task escalation handler " ) {
105+ func triggerTaskEscalationHandler ( ) {
102106 let sem1 = DispatchSemaphore ( value: 0 )
103107 let sem2 = DispatchSemaphore ( value: 0 )
104108 let semEscalated = DispatchSemaphore ( value: 0 )
@@ -134,8 +138,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
134138 semEscalated. wait ( )
135139 sem2. wait ( )
136140 }
141+ await triggerTaskEscalationHandler ( )
137142
138- tests . test ( " Trigger twice: Escalate to medium, and then again to high " ) {
143+ func triggerTwice_escalateToMediumAndThenAgainToHigh ( ) {
139144 let sem1 = DispatchSemaphore ( value: 0 )
140145 let semEscalatedMedium = DispatchSemaphore ( value: 0 )
141146 let semEscalatedHigh = DispatchSemaphore ( value: 0 )
@@ -176,8 +181,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
176181 // we got escalated twice
177182 semEscalatedInHandler. wait ( )
178183 }
184+ await triggerTwice_escalateToMediumAndThenAgainToHigh ( )
179185
180- tests . test ( " Don't trigger in already escalated task " ) {
186+ func dontTriggerInAlreadyEscalatedTask ( ) {
181187 let sem1 = DispatchSemaphore ( value: 0 )
182188 let sem2 = DispatchSemaphore ( value: 0 )
183189 let semEscalated = DispatchSemaphore ( value: 0 )
@@ -219,8 +225,7 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
219225 semEscalated. wait ( )
220226 sem2. wait ( )
221227 }
222-
223- await runAllTestsAsync ( )
228+ await dontTriggerInAlreadyEscalatedTask ( )
224229 }
225230
226231 await top_level. value
0 commit comments