Skip to content

Commit 0000e39

Browse files
committed
[Distributed] NFC: Add more test-cases for generic distributed methods
1 parent 1fc0f3c commit 0000e39

File tree

1 file changed

+117
-11
lines changed

1 file changed

+117
-11
lines changed

test/Distributed/Runtime/distributed_actor_remoteCall.swift

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ struct S<T: Codable> : Codable {
4242
func __isRemoteActor(_ actor: AnyObject) -> Bool
4343

4444
distributed actor Greeter {
45-
distributed func generic1<T: Codable, U: Codable>(t: T, u: U) {
46-
print("---> T = \(t), type(of:) = \(type(of: t))")
47-
print("---> U = \(u), type(of:) = \(type(of: u))")
48-
}
49-
5045
distributed func empty() {
5146
}
5247

@@ -69,6 +64,34 @@ distributed actor Greeter {
6964
distributed func enumResult() -> E {
7065
.bar
7166
}
67+
68+
distributed func generic1<A: Codable>(a: A) {
69+
print("---> A = \(a), type(of:) = \(type(of: a))")
70+
}
71+
72+
distributed func generic2<A: Codable, B: Codable>(a: A, b: B) {
73+
print("---> A = \(a), type(of:) = \(type(of: a))")
74+
print("---> B = \(b), type(of:) = \(type(of: b))")
75+
}
76+
77+
distributed func generic3<A: Codable, B: Codable, C: Codable>(a: A, b: Array<B>, c: C) {
78+
print("---> A = \(a), type(of:) = \(type(of: a))")
79+
print("---> B = \(b), type(of:) = \(type(of: b))")
80+
print("---> C = \(c), type(of:) = \(type(of: c))")
81+
}
82+
83+
distributed func generic4<A: Codable, B: Codable, C: Codable>(a: A, b: S<B>, c: Array<C>) {
84+
print("---> A = \(a), type(of:) = \(type(of: a))")
85+
print("---> B = \(b), type(of:) = \(type(of: b))")
86+
print("---> C = \(c), type(of:) = \(type(of: c))")
87+
}
88+
89+
distributed func generic5<A: Codable, B: Codable, C: Codable, D: Codable>(a: A, b: S<B>, c: C, d: D) {
90+
print("---> A = \(a), type(of:) = \(type(of: a))")
91+
print("---> B = \(b), type(of:) = \(type(of: b))")
92+
print("---> C = \(c), type(of:) = \(type(of: c))")
93+
print("---> D = \(d), type(of:) = \(type(of: d))")
94+
}
7295
}
7396

7497

@@ -201,8 +224,11 @@ let answerName = "$s4main7GreeterC6answerSiyFTE"
201224
let largeResultName = "$s4main7GreeterC11largeResultAA11LargeStructVyFTE"
202225
let enumResultName = "$s4main7GreeterC10enumResultAA1EOyFTE"
203226
let echoName = "$s4main7GreeterC4echo4name3ageS2S_SitFTE"
204-
// <T: Codable, U: Codable>(t: T, u: U)
205-
let generic1Name = "$s4main7GreeterC8generic11t1uyx_q_tSeRzSERzSeR_SER_r0_lFTE"
227+
let generic1Name = "$s4main7GreeterC8generic11ayx_tSeRzSERzlFTE"
228+
let generic2Name = "$s4main7GreeterC8generic21a1byx_q_tSeRzSERzSeR_SER_r0_lFTE"
229+
let generic3Name = "$s4main7GreeterC8generic31a1b1cyx_Sayq_Gq0_tSeRzSERzSeR_SER_SeR0_SER0_r1_lFTE"
230+
let generic4Name = "$s4main7GreeterC8generic41a1b1cyx_AA1SVyq_GSayq0_GtSeRzSERzSeR_SER_SeR0_SER0_r1_lFTE"
231+
let generic5Name = "$s4main7GreeterC8generic51a1b1c1dyx_AA1SVyq_Gq0_q1_tSeRzSERzSeR_SER_SeR0_SER0_SeR1_SER1_r2_lFTE"
206232

207233
func test() async throws {
208234
let system = FakeActorSystem()
@@ -267,9 +293,7 @@ func test() async throws {
267293
var generic1Invocation = system.makeInvocationEncoder()
268294

269295
try generic1Invocation.recordGenericSubstitution(Int.self)
270-
try generic1Invocation.recordGenericSubstitution(String.self)
271296
try generic1Invocation.recordArgument(42)
272-
try generic1Invocation.recordArgument("Ultimate Question!")
273297
try generic1Invocation.doneRecording()
274298

275299
try await system.executeDistributedTarget(
@@ -278,9 +302,91 @@ func test() async throws {
278302
invocationDecoder: &generic1Invocation,
279303
handler: FakeResultHandler()
280304
)
305+
// CHECK: ---> A = 42, type(of:) = Int
306+
// CHECK-NEXT: RETURN: ()
307+
308+
var generic2Invocation = system.makeInvocationEncoder()
309+
310+
try generic2Invocation.recordGenericSubstitution(Int.self)
311+
try generic2Invocation.recordGenericSubstitution(String.self)
312+
try generic2Invocation.recordArgument(42)
313+
try generic2Invocation.recordArgument("Ultimate Question!")
314+
try generic2Invocation.doneRecording()
315+
316+
try await system.executeDistributedTarget(
317+
on: local,
318+
mangledTargetName: generic2Name,
319+
invocationDecoder: &generic2Invocation,
320+
handler: FakeResultHandler()
321+
)
322+
// CHECK: ---> A = 42, type(of:) = Int
323+
// CHECK-NEXT: ---> B = Ultimate Question!, type(of:) = String
324+
// CHECK-NEXT: RETURN: ()
325+
326+
var generic3Invocation = system.makeInvocationEncoder()
281327

282-
// CHECK: ---> T = 42, type(of:) = Int
283-
// CHECK-NEXT: ---> U = Ultimate Question!, type(of:) = String
328+
try generic3Invocation.recordGenericSubstitution(Int.self)
329+
try generic3Invocation.recordGenericSubstitution(String.self)
330+
try generic3Invocation.recordGenericSubstitution(S<Int>.self)
331+
try generic3Invocation.recordArgument(42)
332+
try generic3Invocation.recordArgument(["a", "b", "c"])
333+
try generic3Invocation.recordArgument(S(data: 42))
334+
try generic3Invocation.doneRecording()
335+
336+
try await system.executeDistributedTarget(
337+
on: local,
338+
mangledTargetName: generic3Name,
339+
invocationDecoder: &generic3Invocation,
340+
handler: FakeResultHandler()
341+
)
342+
// CHECK: ---> A = 42, type(of:) = Int
343+
// CHECK-NEXT: ---> B = ["a", "b", "c"], type(of:) = Array<String>
344+
// CHECK-NEXT: ---> C = S<Int>(data: 42), type(of:) = S<Int>
345+
// CHECK-NEXT: RETURN: ()
346+
347+
var generic4Invocation = system.makeInvocationEncoder()
348+
349+
try generic4Invocation.recordGenericSubstitution(Int.self)
350+
try generic4Invocation.recordGenericSubstitution(Int.self)
351+
try generic4Invocation.recordGenericSubstitution(String.self)
352+
try generic4Invocation.recordArgument(42)
353+
try generic4Invocation.recordArgument(S(data: 42))
354+
try generic4Invocation.recordArgument(["a", "b", "c"])
355+
try generic4Invocation.doneRecording()
356+
357+
try await system.executeDistributedTarget(
358+
on: local,
359+
mangledTargetName: generic4Name,
360+
invocationDecoder: &generic4Invocation,
361+
handler: FakeResultHandler()
362+
)
363+
// CHECK: ---> A = 42, type(of:) = Int
364+
// CHECK-NEXT: ---> B = S<Int>(data: 42), type(of:) = S<Int>
365+
// CHECK-NEXT: ---> C = ["a", "b", "c"], type(of:) = Array<String>
366+
// CHECK-NEXT: RETURN: ()
367+
368+
var generic5Invocation = system.makeInvocationEncoder()
369+
370+
try generic5Invocation.recordGenericSubstitution(Int.self)
371+
try generic5Invocation.recordGenericSubstitution(Int.self)
372+
try generic5Invocation.recordGenericSubstitution(String.self)
373+
try generic5Invocation.recordGenericSubstitution([Double].self)
374+
try generic5Invocation.recordArgument(42)
375+
try generic5Invocation.recordArgument(S(data: 42))
376+
try generic5Invocation.recordArgument("Hello, World!")
377+
try generic5Invocation.recordArgument([0.0, 0xdecafbad])
378+
try generic5Invocation.doneRecording()
379+
380+
try await system.executeDistributedTarget(
381+
on: local,
382+
mangledTargetName: generic5Name,
383+
invocationDecoder: &generic5Invocation,
384+
handler: FakeResultHandler()
385+
)
386+
// CHECK: ---> A = 42, type(of:) = Int
387+
// CHECK-NEXT: ---> B = S<Int>(data: 42), type(of:) = S<Int>
388+
// CHECK-NEXT: ---> C = Hello, World!, type(of:) = String
389+
// CHECK-NEXT: ---> D = [0.0, 3737844653.0], type(of:) = Array<Double>
284390
// CHECK-NEXT: RETURN: ()
285391

286392
print("done")

0 commit comments

Comments
 (0)