|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift |
| 3 | +// RUN: %target-build-swift -module-name main -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out |
| 4 | +// RUN: %target-codesign %t/a.out |
| 5 | +// RUN: %target-run %t/a.out |
| 6 | + |
| 7 | +// REQUIRES: executable_test |
| 8 | +// REQUIRES: concurrency |
| 9 | +// REQUIRES: distributed |
| 10 | + |
| 11 | +// rdar://76038845 |
| 12 | +// UNSUPPORTED: use_os_stdlib |
| 13 | +// UNSUPPORTED: back_deployment_runtime |
| 14 | +// UNSUPPORTED: freestanding |
| 15 | + |
| 16 | +// FIXME(distributed): Distributed actors currently have some issues on windows rdar://82593574 |
| 17 | +// UNSUPPORTED: OS=windows-msvc |
| 18 | + |
| 19 | +import StdlibUnittest |
| 20 | +import Distributed |
| 21 | +import FakeDistributedActorSystems |
| 22 | + |
| 23 | +@available(SwiftStdlib 5.9, *) |
| 24 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 25 | + |
| 26 | +@available(SwiftStdlib 5.9, *) |
| 27 | +func globalFunc(isolatedTo actor: isolated any DistributedActor) async { |
| 28 | + MainActor.preconditionIsolated() // we forced the `actor` onto the main actor's executor |
| 29 | +} |
| 30 | + |
| 31 | +@available(SwiftStdlib 5.9, *) // because conforming to the protocol requirement introduced in 5.9 |
| 32 | +distributed actor NormalWorker { |
| 33 | + |
| 34 | + nonisolated var unownedExecutor: UnownedSerialExecutor { |
| 35 | + return MainActor.sharedUnownedExecutor |
| 36 | + } |
| 37 | + |
| 38 | + distributed func offerSelf() async { |
| 39 | + print("executed: \(#function)") |
| 40 | + MainActor.preconditionIsolated() // we forced the `actor` onto the main actor's executor |
| 41 | + |
| 42 | + await globalFunc(isolatedTo: self) |
| 43 | + MainActor.preconditionIsolated() // we forced the `actor` onto the main actor's executor |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +@available(SwiftStdlib 5.1, *) |
| 48 | +@main struct Main { |
| 49 | + @available(SwiftStdlib 5.1, *) |
| 50 | + static func main() async { |
| 51 | + if #available(SwiftStdlib 5.9, *) { |
| 52 | + let tests = TestSuite("DistributedIsolatedTests") |
| 53 | + let system = DefaultDistributedActorSystem() |
| 54 | + let normalLocalWorker = NormalWorker(actorSystem: system) |
| 55 | + precondition(__isLocalActor(normalLocalWorker), "must be local") |
| 56 | + |
| 57 | + tests.test("remote actor reference should have crash-on-enqueue executor") { |
| 58 | + try! await normalLocalWorker.offerSelf() |
| 59 | + } |
| 60 | + |
| 61 | + await runAllTestsAsync() |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments