Skip to content

Commit 620a541

Browse files
authored
[Distributed] fix all distributed runtime tests; they are currently not running on CI (#38502)
1 parent 5c22dd5 commit 620a541

8 files changed

+204
-131
lines changed

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ extension DistributedActor {
126126
public protocol ActorIdentity: Sendable, Hashable, Codable {}
127127

128128
@available(SwiftStdlib 5.5, *)
129-
public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
129+
public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable, CustomStringConvertible {
130130
@usableFromInline let _hashInto: (inout Hasher) -> ()
131131
@usableFromInline let _equalTo: (Any) -> Bool
132132
@usableFromInline let _encodeTo: (Encoder) throws -> ()
133+
@usableFromInline let _description: () -> String
133134

134135
public init<ID>(_ identity: ID) where ID: ActorIdentity {
135-
_hashInto = { hasher in identity.hash(into: &hasher) }
136+
_hashInto = { hasher in identity
137+
.hash(into: &hasher)
138+
}
136139
_equalTo = { other in
137140
guard let rhs = other as? ID else {
138141
return false
@@ -142,6 +145,9 @@ public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
142145
_encodeTo = { encoder in
143146
try identity.encode(to: encoder)
144147
}
148+
_description = { () in
149+
"\(identity)"
150+
}
145151
}
146152

147153
public init(from decoder: Decoder) throws {
@@ -158,6 +164,10 @@ public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
158164
try _encodeTo(encoder)
159165
}
160166

167+
public var description: String {
168+
"\(Self.self)(\(self._description()))"
169+
}
170+
161171
public func hash(into hasher: inout Hasher) {
162172
_hashInto(&hasher)
163173
}

test/Distributed/Runtime/distributed_actor_deinit.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// UNSUPPORTED: use_os_stdlib
88
// UNSUPPORTED: back_deployment_runtime
99

10-
// REQUIRES: radar78290608
10+
// REQUIRES: rdar78290608
1111

1212
import _Distributed
1313

@@ -97,27 +97,27 @@ func test() {
9797

9898
_ = DA(transport: transport)
9999
// CHECK: assign type:DA, address:[[ADDRESS:.*]]
100-
// CHECK: ready actor:main.DA, address:[[ADDRESS]]
101-
// CHECK: resign address:[[ADDRESS]]
100+
// CHECK: ready actor:main.DA, address:AnyActorIdentity(ActorAddress(address: "xxx"))
101+
// CHECK: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))
102102

103103
_ = DA_userDefined(transport: transport)
104104
// CHECK: assign type:DA_userDefined, address:[[ADDRESS:.*]]
105-
// CHECK: ready actor:main.DA_userDefined, address:[[ADDRESS]]
106-
// CHECK: resign address:[[ADDRESS]]
105+
// CHECK: ready actor:main.DA_userDefined, address:AnyActorIdentity(ActorAddress(address: "xxx"))
106+
// CHECK: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))
107107

108108
// resign must happen as the _last thing_ after user-deinit completed
109109
_ = DA_userDefined2(transport: transport)
110110
// CHECK: assign type:DA_userDefined2, address:[[ADDRESS:.*]]
111-
// CHECK: ready actor:main.DA_userDefined2, address:[[ADDRESS]]
112-
// CHECK: Deinitializing [[ADDRESS]]
113-
// CHECK-NEXT: resign address:[[ADDRESS]]
111+
// CHECK: ready actor:main.DA_userDefined2, address:AnyActorIdentity(ActorAddress(address: "xxx"))
112+
// CHECK: Deinitializing AnyActorIdentity(ActorAddress(address: "xxx"))
113+
// CHECK-NEXT: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))
114114

115115
// resign must happen as the _last thing_ after user-deinit completed
116116
_ = DA_state(transport: transport)
117117
// CHECK: assign type:DA_state, address:[[ADDRESS:.*]]
118-
// CHECK: ready actor:main.DA_state, address:[[ADDRESS]]
119-
// CHECK: Deinitializing [[ADDRESS]]
120-
// CHECK-NEXT: resign address:[[ADDRESS]]
118+
// CHECK: ready actor:main.DA_state, address:AnyActorIdentity(ActorAddress(address: "xxx"))
119+
// CHECK: Deinitializing AnyActorIdentity(ActorAddress(address: "xxx"))
120+
// CHECK-NEXT: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))
121121

122122
// a remote actor should not resign it's address, it was never "assigned" it
123123
print("before")

test/Distributed/Runtime/distributed_actor_dynamic_remote_func.swift

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// UNSUPPORTED: use_os_stdlib
88
// UNSUPPORTED: back_deployment_runtime
99

10-
// REQUIRES: radar78290608
10+
// REQUIRES: rdar78290608
1111

1212
import _Distributed
1313

@@ -39,6 +39,7 @@ extension LocalWorker {
3939

4040
// ==== Fake Transport ---------------------------------------------------------
4141

42+
4243
@available(SwiftStdlib 5.5, *)
4344
struct ActorAddress: ActorIdentity {
4445
let address: String
@@ -49,29 +50,29 @@ struct ActorAddress: ActorIdentity {
4950

5051
@available(SwiftStdlib 5.5, *)
5152
struct FakeTransport: ActorTransport {
52-
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
53-
throws -> ActorResolved<Act> where Act: DistributedActor {
54-
fatalError()
53+
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
54+
fatalError("not implemented:\(#function)")
55+
}
56+
57+
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
58+
throws -> ActorResolved<Act>
59+
where Act: DistributedActor {
60+
.makeProxy
5561
}
5662

57-
func assignIdentity<Act>(
58-
_ actorType: Act.Type
59-
) -> ActorAddress where Act : DistributedActor {
60-
let address = ActorAddress(parse: "xxx")
61-
print("assign type:\(actorType), address:\(address)")
62-
return address
63+
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
64+
where Act: DistributedActor {
65+
let id = ActorAddress(parse: "xxx")
66+
print("assign type:\(actorType), id:\(id)")
67+
return .init(id)
6368
}
6469

65-
public func actorReady<Act>(
66-
_ actor: Act
67-
) where Act: DistributedActor {
68-
print("ready actor:\(actor), address:\(actor.id)")
70+
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
71+
print("ready actor:\(actor), id:\(actor.id)")
6972
}
7073

71-
public func resignIdentity(
72-
_ address: ActorAddress
73-
) {
74-
print("ready address:\(address)")
74+
func resignIdentity(_ id: AnyActorIdentity) {
75+
print("ready id:\(id)")
7576
}
7677
}
7778

@@ -84,8 +85,8 @@ func test_local() async throws {
8485
let worker = LocalWorker(transport: transport)
8586
let x = try await worker.function()
8687
print("call: \(x)")
87-
// CHECK: assign type:LocalWorker, address:[[ADDRESS:.*]]
88-
// CHECK: ready actor:main.LocalWorker, address:[[ADDRESS]]
88+
// CHECK: assign type:LocalWorker, id:[[ADDRESS:.*]]
89+
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity([[ADDRESS]])
8990
// CHECK: call: local:
9091
}
9192

@@ -94,7 +95,7 @@ func test_remote() async throws {
9495
let address = ActorAddress(parse: "")
9596
let transport = FakeTransport()
9697

97-
let worker = try LocalWorker(resolve: address, using: transport)
98+
let worker = try LocalWorker(resolve: .init(address), using: transport)
9899
let x = try await worker.function()
99100
print("call: \(x)")
100101
// CHECK: call: _cluster_remote_function():

test/Distributed/Runtime/distributed_actor_init_local.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
// REQUIRES: radar78290608
11+
// REQUIRES: rdar78290608
1212

1313
import _Distributed
1414

@@ -28,29 +28,29 @@ struct ActorAddress: ActorIdentity {
2828

2929
@available(SwiftStdlib 5.5, *)
3030
struct FakeTransport: ActorTransport {
31-
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
32-
throws -> ActorResolved<Act> where Act: DistributedActor {
33-
fatalError()
31+
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
32+
fatalError("not implemented:\(#function)")
3433
}
3534

36-
func assignIdentity<Act>(
37-
_ actorType: Act.Type
38-
) -> ActorAddress where Act : DistributedActor {
39-
let address = ActorAddress(parse: "xxx")
40-
print("assign type:\(actorType), address:\(address)")
41-
return address
35+
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
36+
throws -> ActorResolved<Act>
37+
where Act: DistributedActor {
38+
fatalError("not implemented:\(#function)")
4239
}
4340

44-
public func actorReady<Act>(
45-
_ actor: Act
46-
) where Act: DistributedActor {
47-
print("ready actor:\(actor), address:\(actor.id)")
41+
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
42+
where Act: DistributedActor {
43+
let id = ActorAddress(parse: "xxx")
44+
print("assign type:\(actorType), id:\(id)")
45+
return .init(id)
4846
}
4947

50-
public func resignIdentity(
51-
_ address: ActorAddress
52-
) {
53-
print("ready address:\(address)")
48+
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
49+
print("ready actor:\(actor), id:\(actor.id)")
50+
}
51+
52+
func resignIdentity(_ id: AnyActorIdentity) {
53+
print("ready id:\(id)")
5454
}
5555
}
5656

@@ -61,8 +61,8 @@ func test() {
6161
let transport = FakeTransport()
6262

6363
_ = LocalWorker(transport: transport)
64-
// CHECK: assign type:LocalWorker, address:[[ADDRESS:.*]]
65-
// CHECK: ready actor:main.LocalWorker, address:[[ADDRESS]]
64+
// CHECK: assign type:LocalWorker, id:[[ID:.*]]
65+
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity([[ID]])
6666
}
6767

6868
@available(SwiftStdlib 5.5, *)

test/Distributed/Runtime/distributed_actor_isRemote.swift

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// rdar://77798215
1212
// UNSUPPORTED: OS=windows-msvc
1313

14-
// REQUIRES: radar78290608
14+
// REQUIRES: rdar78290608
1515

1616
import _Distributed
1717

@@ -25,9 +25,9 @@ distributed actor SomeSpecificDistributedActor {
2525
@available(SwiftStdlib 5.5, *)
2626
extension SomeSpecificDistributedActor {
2727

28-
@_dynamicReplacement(for: hello())
29-
nonisolated func _remote_hello() async throws -> String {
30-
return "remote impl (address: \(actor.id))"
28+
@_dynamicReplacement(for: _remote_hello())
29+
nonisolated func _remote_impl_hello() async throws -> String {
30+
return "remote impl (address: \(self.id))"
3131
}
3232
}
3333

@@ -40,30 +40,43 @@ struct FakeActorID: ActorIdentity {
4040

4141
@available(SwiftStdlib 5.5, *)
4242
enum FakeTransportError: ActorTransportError {
43-
case unsupportedActorIdentity(ActorIdentity)
43+
case unsupportedActorIdentity(AnyActorIdentity)
44+
}
45+
46+
@available(SwiftStdlib 5.5, *)
47+
struct ActorAddress: ActorIdentity {
48+
let address: String
49+
init(parse address : String) {
50+
self.address = address
51+
}
4452
}
4553

4654
@available(SwiftStdlib 5.5, *)
4755
struct FakeTransport: ActorTransport {
48-
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
49-
throws -> ActorResolved<Act> where Act: DistributedActor {
50-
return .makeProxy
56+
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
57+
fatalError("not implemented:\(#function)")
5158
}
5259

53-
func assignIdentity<Act>(
54-
_ actorType: Act.Type
55-
) -> ActorAddress where Act : DistributedActor {
56-
ActorAddress(parse: "")
60+
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
61+
throws -> ActorResolved<Act>
62+
where Act: DistributedActor {
63+
.makeProxy
5764
}
5865

59-
public func actorReady<Act>(
60-
_ actor: Act
61-
) where Act: DistributedActor {}
66+
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
67+
where Act: DistributedActor {
68+
let id = ActorAddress(parse: "xxx")
69+
print("assign type:\(actorType), id:\(id)")
70+
return .init(id)
71+
}
6272

63-
public func resignIdentity(
64-
_ address: AnyActorIdentity
65-
) {}
73+
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
74+
print("ready actor:\(actor), id:\(actor.id)")
75+
}
6676

77+
func resignIdentity(_ id: AnyActorIdentity) {
78+
print("ready id:\(id)")
79+
}
6780
}
6881

6982
// ==== Execute ----------------------------------------------------------------
@@ -88,7 +101,7 @@ func test_remote() async {
88101
assert(__isRemoteActor(local) == false, "should be local")
89102

90103
// assume it always makes a remote one
91-
let remote = try! SomeSpecificDistributedActor(resolve: address, using: transport)
104+
let remote = try! SomeSpecificDistributedActor(resolve: .init(address), using: transport)
92105
assert(__isLocalActor(remote) == false, "should be remote")
93106
assert(__isRemoteActor(remote) == true, "should be remote")
94107

test/Distributed/Runtime/distributed_actor_local.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
// REQUIRES: radar78290608
11+
// REQUIRES: rdar78290608
1212

1313
import _Distributed
1414

@@ -18,6 +18,10 @@ distributed actor SomeSpecificDistributedActor {
1818
distributed func hello() async throws {
1919
print("hello from \(self.id)")
2020
}
21+
22+
distributed func echo(int: Int) async throws -> Int {
23+
int
24+
}
2125
}
2226

2327
// ==== Execute ----------------------------------------------------------------
@@ -41,25 +45,23 @@ struct ActorAddress: ActorIdentity {
4145

4246
@available(SwiftStdlib 5.5, *)
4347
struct FakeTransport: ActorTransport {
44-
4548
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
46-
fatalError()
49+
fatalError("not implemented \(#function)")
4750
}
4851

49-
func resolve<Act>(identity: Act.ID, as actorType: Act.Type)
50-
throws -> ActorResolved<Act>
52+
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type) throws -> ActorResolved<Act>
5153
where Act: DistributedActor {
52-
fatalError()
54+
return .makeProxy
5355
}
5456

5557
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
5658
where Act: DistributedActor {
57-
ActorAddress(parse: "")
59+
.init(ActorAddress(parse: ""))
5860
}
5961

6062
public func actorReady<Act>(_ actor: Act)
6163
where Act: DistributedActor {
62-
fatalError()
64+
print("\(#function):\(actor)")
6365
}
6466

6567
func resignIdentity(_ id: AnyActorIdentity) {}
@@ -73,7 +75,7 @@ func test_initializers() {
7375
let transport = FakeTransport()
7476

7577
_ = SomeSpecificDistributedActor(transport: transport)
76-
_ = try! SomeSpecificDistributedActor.resolve(address, using: transport)
78+
_ = try! SomeSpecificDistributedActor(resolve: .init(address), using: transport)
7779
}
7880

7981
@available(SwiftStdlib 5.5, *)

0 commit comments

Comments
 (0)