|
| 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 -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 --dump-input=always |
| 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 | +import Distributed |
| 18 | +import FakeDistributedActorSystems |
| 19 | + |
| 20 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 21 | + |
| 22 | +distributed actor Greeter { |
| 23 | + distributed func usedToHaveAsyncBytNotAnymore() |
| 24 | + /*previously had async, and remote called invoked such async method */ -> String { |
| 25 | + return #function |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +distributed actor Helloer { |
| 30 | + distributed func usedToBeSyncButNowIsAsync() |
| 31 | + /* The remote caller thinks this method was not async, but actually it is */ |
| 32 | + async -> String { |
| 33 | + return #function |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func test_usedToBeAsync_but_remoteImplIsNotAnymore() async throws { |
| 38 | + let system = DefaultDistributedActorSystem() |
| 39 | + |
| 40 | + let local = Greeter(actorSystem: system) |
| 41 | + let remote = try Greeter.resolve(id: local.id, using: system) |
| 42 | + |
| 43 | + var invocation = FakeInvocationEncoder() |
| 44 | + // let reply = try await remote.usedToHaveAsyncBytNotAnymore() |
| 45 | + let reply: String = try await system.remoteCall( |
| 46 | + on: remote, |
| 47 | + // Important: notice the mangling has a YaK here, since we mangled |
| 48 | + // based on the distributed thunk, which is 'async throws' (YaK). |
| 49 | + // |
| 50 | + // This test is about ensuring, that even if a remote recipient process, |
| 51 | + // changed their implementation from async to not async, we're still able |
| 52 | + // to invoke them. From the perspective of the remote caller it truly does |
| 53 | + // not matter how the recipient implements this call: is it async or not, |
| 54 | + // and we should not tie ability to invoke a method to it's asyncness. |
| 55 | + // |
| 56 | + // Note also that a remote call is always async and throws as well, |
| 57 | + // so mangling based on the 'async throws' thunk does not introduce |
| 58 | + // unexpected effects in remote calls. |
| 59 | + // |
| 60 | + // Design limitation by choice: this means we cannot |
| 61 | + target: RemoteCallTarget("$s4main7GreeterC28usedToHaveAsyncBytNotAnymoreSSyYaKFTE"), |
| 62 | + invocation: &invocation, |
| 63 | + throwing: Never.self, |
| 64 | + returning: String.self |
| 65 | + ) |
| 66 | + |
| 67 | + // CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.usedToHaveAsyncBytNotAnymore(), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [], returnType: nil, errorType: nil), throwing:Swift.Never, returning:Swift.String |
| 68 | + // CHECK: << onReturn: usedToHaveAsyncBytNotAnymore() |
| 69 | + |
| 70 | + print("reply: \(reply)") // CHECK: reply: usedToHaveAsyncBytNotAnymore() |
| 71 | +} |
| 72 | + |
| 73 | +func test_usedToBeSync_but_remoteImplIsAsyncNow() async throws { |
| 74 | + let system = DefaultDistributedActorSystem() |
| 75 | + |
| 76 | + let local = Helloer(actorSystem: system) |
| 77 | + let remote = try Helloer.resolve(id: local.id, using: system) |
| 78 | + |
| 79 | + var invocation = FakeInvocationEncoder() |
| 80 | + // let reply: String = try await remote.usedToBeSyncButNowIsAsync() |
| 81 | + let reply: String = try await system.remoteCall( |
| 82 | + on: remote, |
| 83 | + target: RemoteCallTarget("$s4main7HelloerC25usedToBeSyncButNowIsAsyncSSyYaKFTE"), |
| 84 | + invocation: &invocation, |
| 85 | + throwing: Never.self, |
| 86 | + returning: String.self |
| 87 | + ) |
| 88 | + |
| 89 | + // CHECK: >> remoteCall: on:main.Helloer, target:main.Helloer.usedToBeSyncButNowIsAsync(), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [], returnType: nil, errorType: nil), throwing:Swift.Never, returning:Swift.String |
| 90 | + // CHECK: << onReturn: usedToBeSyncButNowIsAsync() |
| 91 | + |
| 92 | + print("reply: \(reply)") // CHECK: reply: usedToBeSyncButNowIsAsync() |
| 93 | +} |
| 94 | + |
| 95 | +@main struct Main { |
| 96 | + static func main() async { |
| 97 | + try! await test_usedToBeAsync_but_remoteImplIsNotAnymore() |
| 98 | + try! await test_usedToBeSync_but_remoteImplIsAsyncNow() |
| 99 | + } |
| 100 | +} |
0 commit comments