|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend-emit-module -plugin-path %swift-plugin-dir -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift |
| 3 | +// RUN: %target-build-swift -module-name main -plugin-path %swift-plugin-dir -target %target-swift-5.7-abi-triple -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 | %FileCheck %s |
| 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 | + |
| 15 | +// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574 |
| 16 | +// UNSUPPORTED: OS=windows-msvc |
| 17 | + |
| 18 | +import Distributed |
| 19 | +import FakeDistributedActorSystems |
| 20 | + |
| 21 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 22 | + |
| 23 | +@Resolvable |
| 24 | +@available(SwiftStdlib 6.0, *) |
| 25 | +protocol GreeterProtocol: DistributedActor where ActorSystem == FakeRoundtripActorSystem { |
| 26 | + distributed func method(_ value: [Int]) -> String |
| 27 | +} |
| 28 | + |
| 29 | +@available(SwiftStdlib 6.0, *) |
| 30 | +distributed actor Greeter: GreeterProtocol { |
| 31 | + distributed func method(_ value: [Int]) -> String { |
| 32 | + return "\(value)" |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +@available(SwiftStdlib 6.0, *) |
| 37 | +func test() async throws { |
| 38 | + let system = DefaultDistributedActorSystem() |
| 39 | + |
| 40 | + let local = Greeter(actorSystem: system) |
| 41 | + let ref = try Greeter.resolve(id: local.id, using: system) |
| 42 | + |
| 43 | + let r1 = try await ref.method([1, 2, 3]) |
| 44 | + // CHECK: > encode argument name:_, value: [1, 2, 3] |
| 45 | + // CHECK: > encode return type: Swift.String |
| 46 | + // CHECK: > done recording |
| 47 | + // CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.method(_:), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [[NUMS:.*]], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String |
| 48 | + print("reply: \(r1)") |
| 49 | + // CHECK: reply: [1, 2, 3] |
| 50 | + |
| 51 | + let ref2 = try $GreeterProtocol.resolve(id: local.id, using: system) |
| 52 | + let r2 = try await ref2.method([1, 2, 3]) |
| 53 | + // CHECK: > execute distributed target: main.$GreeterProtocol.method(_:), identifier: $s4main16$GreeterProtocolC6methodySSSaySiGYaKFTE |
| 54 | + // CHECK: > decode generic subs: [main.$GreeterProtocol] |
| 55 | + // CHECK: > decode return type: Swift.String |
| 56 | + print("reply: \(r2)") |
| 57 | + // CHECK: reply: [1, 2, 3] |
| 58 | + |
| 59 | + |
| 60 | +} |
| 61 | + |
| 62 | +@available(SwiftStdlib 6.0, *) |
| 63 | +@main struct Main { |
| 64 | + static func main() async { |
| 65 | + try! await test() |
| 66 | + } |
| 67 | +} |
0 commit comments