Skip to content

Commit c8b4e8e

Browse files
authored
[Distributed] More tests for local actor init, with specific transport type (#39788)
1 parent 338cc32 commit c8b4e8e

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

test/Distributed/distributed_actor_initialization.swift

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,27 @@
44

55
import _Distributed
66

7-
@available(SwiftStdlib 5.5, *)
87
distributed actor OK0 { }
98

10-
@available(SwiftStdlib 5.5, *)
119
distributed actor OK1 {
1210
var x: Int = 1
1311
// ok, since all fields are initialized, the constructor can be synthesized
1412
}
1513

1614
// TODO(distributed): test all the FIXITs in this file
1715

18-
@available(SwiftStdlib 5.5, *)
1916
distributed actor Bad1 {
2017
init() {
2118
// expected-error@-1 {{designated distributed actor initializer 'init()' is missing required ActorTransport parameter}}
2219
}
2320
}
2421

25-
@available(SwiftStdlib 5.5, *)
2622
distributed actor Bad12 {
2723
init(x: String) {
2824
// expected-error@-1 {{designated distributed actor initializer 'init(x:)' is missing required ActorTransport parameter}}
2925
}
3026
}
3127

32-
@available(SwiftStdlib 5.5, *)
3328
distributed actor OK2 {
3429
var x: Int
3530

@@ -38,7 +33,6 @@ distributed actor OK2 {
3833
}
3934
}
4035

41-
@available(SwiftStdlib 5.5, *)
4236
distributed actor Bad2 {
4337
var x: Int = 1
4438

@@ -47,7 +41,6 @@ distributed actor Bad2 {
4741
}
4842
}
4943

50-
@available(SwiftStdlib 5.5, *)
5144
distributed actor OK3 {
5245
var x: Int
5346

@@ -56,11 +49,60 @@ distributed actor OK3 {
5649
}
5750
}
5851

59-
@available(SwiftStdlib 5.5, *)
6052
distributed actor OKMulti {
6153

6254
convenience init(y: Int, transport: ActorTransport) { // ok
6355
self.init(transport: transport)
6456
}
6557

6658
}
59+
60+
distributed actor OKMultiDefaultValues {
61+
62+
convenience init(y: Int, transport: ActorTransport, x: Int = 1234) { // ok
63+
self.init(transport: transport)
64+
}
65+
66+
}
67+
68+
// ==== ------------------------------------------------------------------------
69+
// MARK: Specific transport
70+
71+
struct ActorAddress: ActorIdentity {
72+
let address: String
73+
init(parse address : String) {
74+
self.address = address
75+
}
76+
}
77+
78+
struct FakeTransport: ActorTransport {
79+
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
80+
fatalError("not implemented \(#function)")
81+
}
82+
83+
func resolve<Act>(_ identity: AnyActorIdentity, as actorType: Act.Type) throws -> Act?
84+
where Act: DistributedActor {
85+
return nil
86+
}
87+
88+
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
89+
where Act: DistributedActor {
90+
.init(ActorAddress(parse: ""))
91+
}
92+
93+
public func actorReady<Act>(_ actor: Act)
94+
where Act: DistributedActor {
95+
print("\(#function):\(actor)")
96+
}
97+
98+
func resignIdentity(_ id: AnyActorIdentity) {}
99+
}
100+
101+
distributed actor OKSpecificTransportType {
102+
103+
init(y: Int, transport fake: FakeTransport) { // ok
104+
defer { fake.actorReady(self) }
105+
// nothing
106+
}
107+
108+
}

0 commit comments

Comments
 (0)