Skip to content

Commit

Permalink
Priority avoidance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Aug 16, 2024
1 parent 0413a40 commit 9beb5d3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Tests/QueueTests/AsyncQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,38 @@ extension AsyncQueueTests {
}
}
}

func testPriorityInversionAvoidance() async throws {
let queue = AsyncQueue(attributes: [.concurrent])

let exp = expectation(description: "low priority task executed")

queue.addOperation(priority: .low) {
try await delay(milliseconds: 100)

XCTAssertTrue(Task.currentPriority >= .high)
exp.fulfill()
}

let task = queue.addOperation(priority: .high, barrier: true) {
XCTAssertTrue(Task.currentPriority >= .high)
}

await task.value
await fulfillment(of: [exp], timeout: 1.0)
}

func testLowPriority() async throws {
let queue = AsyncQueue(attributes: [.concurrent])

let exp = expectation(description: "low priority task executed")

queue.addOperation(priority: .low) {
XCTAssertTrue(Task.currentPriority == .low)

exp.fulfill()
}

await fulfillment(of: [exp], timeout: 1.0)
}
}

0 comments on commit 9beb5d3

Please sign in to comment.