Files
swift-mirror/test/Distributed/Runtime/distributed_actor_whenLocal.swift
Allan Shortlidge 75bad99f78 Tests: Remove -disable-availability-checking in Distributed tests.
Use the `%target-swift-5.X-abi-triple` substitutions to compile the tests for
deployment to the minimum OS versions required for the APIs used in the tests,
instead of disabling availability checking.
2024-10-20 09:07:13 -07:00

55 lines
1.7 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-build-swift -module-name main -target %target-swift-5.7-abi-triple -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed
// rdar://76038845
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
// UNSUPPORTED: OS=windows-msvc
import Distributed
distributed actor Capybara {
// only the local capybara can do this!
func eat() -> String {
"watermelon"
}
}
typealias DefaultDistributedActorSystem = FakeActorSystem
func test() async throws {
let system = DefaultDistributedActorSystem()
let local = Capybara(actorSystem: system)
// await local.eat() // SHOULD ERROR
let valueWhenLocal: String? = await local.whenLocal { __secretlyKnownToBeLocal in
__secretlyKnownToBeLocal.eat()
}
// CHECK: valueWhenLocal: watermelon
print("valueWhenLocal: \(valueWhenLocal ?? "nil")")
let remote = try Capybara.resolve(id: local.id, using: system)
let valueWhenRemote: String? = await remote.whenLocal { __secretlyKnownToBeLocal in
__secretlyKnownToBeLocal.eat()
}
// CHECK: valueWhenRemote: nil
print("valueWhenRemote: \(valueWhenRemote ?? "nil")")
}
@main struct Main {
static func main() async {
try! await test()
}
}