|
| 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 -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out |
| 4 | +// RUN: %target-run %t/a.out | %FileCheck %s --color |
| 5 | + |
| 6 | +// REQUIRES: executable_test |
| 7 | +// REQUIRES: concurrency |
| 8 | +// REQUIRES: distributed |
| 9 | + |
| 10 | +// rdar://76038845 |
| 11 | +// UNSUPPORTED: use_os_stdlib |
| 12 | +// UNSUPPORTED: back_deployment_runtime |
| 13 | + |
| 14 | +// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574 |
| 15 | +// UNSUPPORTED: OS=windows-msvc |
| 16 | + |
| 17 | + |
| 18 | +import Distributed |
| 19 | +import FakeDistributedActorSystems |
| 20 | + |
| 21 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 22 | + |
| 23 | +protocol LifecycleWatch: DistributedActor where ActorSystem == FakeRoundtripActorSystem { |
| 24 | + func terminated(actor id: ID) async |
| 25 | +} |
| 26 | + |
| 27 | +extension LifecycleWatch { |
| 28 | + func watch<T: Codable>(x: Int, _ y: T) async throws { |
| 29 | + // nothing here |
| 30 | + print("executed: \(#function) - x = \(x), y = \(y)") |
| 31 | + } |
| 32 | + |
| 33 | + distributed func test<T: Codable & Sendable>(x: Int, _ y: T) async throws { |
| 34 | + print("executed: \(#function)") |
| 35 | + try await self.watch(x: x, y) |
| 36 | + print("done executed: \(#function)") |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +distributed actor Worker: LifecycleWatch { |
| 41 | + func terminated(actor id: ID) async { |
| 42 | + print("terminated (on \(self.id)): \(id)") |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +@main struct Main { |
| 47 | + static func main() async { |
| 48 | + let worker: any LifecycleWatch = Worker(actorSystem: DefaultDistributedActorSystem()) |
| 49 | + try! await worker.test(x: 42, "on protocol") |
| 50 | + |
| 51 | + // CHECK: executed: test(x:_:) |
| 52 | + // CHECK: executed: watch(x:_:) - x = 42, y = on protocol |
| 53 | + // CHECK: done executed: test(x:_:) |
| 54 | + |
| 55 | + // FIXME: Actor isolation getting with generics is pending implementation #59356 |
| 56 | + do { |
| 57 | + let terminatedID = Worker.ID(parse: "<terminated-id>") |
| 58 | + let __secretlyKnownToBeLocal = worker |
| 59 | + await __secretlyKnownToBeLocal.terminated(actor: terminatedID) |
| 60 | + |
| 61 | + // FIXME: Once the above fixme is solved, use this real code instead: |
| 62 | + // _ = await worker.whenLocal { __secretlyKnownToBeLocal in |
| 63 | + // let terminatedID = Worker.ID(parse: "<terminated-id>") |
| 64 | + // return await __secretlyKnownToBeLocal.terminated(actor: terminatedID) |
| 65 | + // } |
| 66 | + } |
| 67 | + // CHECK: terminated (on ActorAddress(address: "<unique-id>")): ActorAddress(address: "<terminated-id>") |
| 68 | + |
| 69 | + print("OK") // CHECK: OK |
| 70 | + } |
| 71 | +} |
0 commit comments