Skip to content

[Concurrency] dont use StdlibUnittest in async_task_escalate_priority #79603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions test/Concurrency/async_task_escalate_priority.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: %empty-directory(%t)

// RUN: %target-build-swift %s -Xfrontend -disable-availability-checking -parse-as-library -o %t/async_task_priority
// RUN: %target-codesign %t/async_task_priority
// RUN: %target-run %t/async_task_priority
// RUN: %target-build-swift %s -Xfrontend -disable-availability-checking -parse-as-library -o %t/async_task_escalate_priority
// RUN: %target-codesign %t/async_task_escalate_priority
// RUN: %target-run %t/async_task_escalate_priority

// REQUIRES: VENDOR=apple
// REQUIRES: executable_test
Expand All @@ -24,7 +24,11 @@

import Darwin
@preconcurrency import Dispatch
import StdlibUnittest

func expectEqual(_ l: TaskPriority, _ r: TaskPriority,
function: String = #function, file: String = #fileID, line: UInt = #line) {
precondition(l == r, "Priority [\(l)] did not equal \(r) @ \(file):\(line)(\(function))")
}

func loopUntil(priority: TaskPriority) async {
var loops = 10
Expand Down Expand Up @@ -77,8 +81,7 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {

let top_level = Task.detached { /* To detach from main actor when running work */

let tests = TestSuite("Task Priority escalation")
tests.test("Basic task_escalate when task is running") {
func basicTask_escalateWhenTaskIsRunning() async {
let sem1 = DispatchSemaphore(value: 0)
let sem2 = DispatchSemaphore(value: 0)
let task = Task(priority: .background) {
Expand All @@ -97,8 +100,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
Task.escalatePriority(task, to: .default)
sem2.wait()
}
await basicTask_escalateWhenTaskIsRunning()

tests.test("Trigger task escalation handler") {
func triggerTaskEscalationHandler() {
let sem1 = DispatchSemaphore(value: 0)
let sem2 = DispatchSemaphore(value: 0)
let semEscalated = DispatchSemaphore(value: 0)
Expand Down Expand Up @@ -134,8 +138,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
semEscalated.wait()
sem2.wait()
}
await triggerTaskEscalationHandler()

tests.test("Trigger twice: Escalate to medium, and then again to high") {
func triggerTwice_escalateToMediumAndThenAgainToHigh() {
let sem1 = DispatchSemaphore(value: 0)
let semEscalatedMedium = DispatchSemaphore(value: 0)
let semEscalatedHigh = DispatchSemaphore(value: 0)
Expand Down Expand Up @@ -176,8 +181,9 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
// we got escalated twice
semEscalatedInHandler.wait()
}
await triggerTwice_escalateToMediumAndThenAgainToHigh()

tests.test("Don't trigger in already escalated task") {
func dontTriggerInAlreadyEscalatedTask() {
let sem1 = DispatchSemaphore(value: 0)
let sem2 = DispatchSemaphore(value: 0)
let semEscalated = DispatchSemaphore(value: 0)
Expand Down Expand Up @@ -219,8 +225,7 @@ func testNestedTaskPriority(basePri: TaskPriority, curPri: TaskPriority) async {
semEscalated.wait()
sem2.wait()
}

await runAllTestsAsync()
await dontTriggerInAlreadyEscalatedTask()
}

await top_level.value
Expand Down