Skip to content

Commit 32eccb9

Browse files
committed
Improve actor-counters test to also test priorities.
1 parent 2168f6c commit 32eccb9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/Concurrency/Runtime/actor_counters.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ actor Counter {
3636
}
3737
}
3838

39+
// Produce a random priority.
40+
nonisolated var randomPriority: TaskPriority? {
41+
let priorities: [TaskPriority?] = [ .background, .low, .medium, .high, nil ]
42+
return priorities.randomElement()!
43+
}
3944

4045
@available(SwiftStdlib 5.5, *)
4146
func worker(identity: Int, counters: [Counter], numIterations: Int) async {
@@ -59,8 +64,8 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
5964
var workers: [Task.Handle<Void, Error>] = []
6065
for i in 0..<numWorkers {
6166
workers.append(
62-
detach { [counters] in
63-
await Task.sleep(UInt64.random(in: 0..<100) * 1_000_000)
67+
Task.detached(priority: randomPriority) { [counters] in
68+
await try! Task.sleep(nanoseconds: UInt64.random(in: 0..<100) * 1_000_000)
6469
await worker(identity: i, counters: counters, numIterations: numIterations)
6570
}
6671
)

0 commit comments

Comments
 (0)