Files
swift-mirror/test/Concurrency/Runtime/async.swift
Allan Shortlidge c02fc4724d Tests: Remove -disable-availability-checking from many Concurrency tests.
Instead, use the `%target-swift-5.1-abi-triple` substitution to compile the tests
for deployment to the minimum OS versions required for use of _Concurrency APIs.
2024-10-18 16:21:51 -07:00

73 lines
1.5 KiB
Swift

// RUN: %target-run-simple-swift( -target %target-swift-5.1-abi-triple %import-libdispatch)
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: libdispatch
// rdar://82123254
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime
import Dispatch
import StdlibUnittest
// for sleep
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Android)
import Android
#endif
var asyncTests = TestSuite("Async")
@available(SwiftStdlib 5.1, *)
actor MyActor {
func synchronous() { }
func doSomething(expectedPriority: TaskPriority) {
async {
synchronous() // okay to be synchronous
assert(Task.currentPriority == expectedPriority)
}
}
}
if #available(SwiftStdlib 5.1, *) {
let actor = MyActor()
asyncTests.test("Detach") {
detach(priority: .background) {
async {
assert(Task.currentPriority == .background)
await actor.doSomething(expectedPriority: .background)
}
}
sleep(1)
}
asyncTests.test("MainQueue") {
DispatchQueue.main.async {
async {
assert(Task.currentPriority == .userInitiated)
}
}
sleep(1)
}
asyncTests.test("GlobalDispatchQueue") {
DispatchQueue.global(qos: .utility).async {
async {
#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS))
// Non-Darwin platforms currently lack qos_class_self().
assert(Task.currentPriority == .utility)
#endif
}
}
sleep(1)
}
}
runAllTests()