Skip to content

Commit e6f2d7f

Browse files
committed
=receptionist rdar://97586760 lookup() trying to cast stub actor
1 parent 86893cc commit e6f2d7f

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ extension OpLogDistributedReceptionist: LifecycleWatch {
391391

392392
// self.instrumentation.listingPublished(key: message._key, subscribers: 1, registrations: registrations.count) // TODO(distributed): make the instrumentation calls compatible with distributed actor based types
393393
let guests = Set(registrations.compactMap { versioned in
394-
versioned.actor.underlying as? Guest
394+
try? Guest.resolve(id: versioned.actor.underlying.id as! ActorID, using: self.actorSystem)
395395
})
396396

397397
assert(guests.count == registrations.count, """

Sources/DistributedActors/DistributedActor+Internal.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ extension DistributedActor where ActorSystem == ClusterSystem {
6868
}
6969
}
7070

71-
distributed actor StubDistributedActor {
71+
internal distributed actor StubDistributedActor {
7272
typealias ID = ClusterSystem.ActorID
7373
typealias ActorSystem = ClusterSystem
74-
75-
// TODO: this is just to prevent a DI crash because of enums without cases and Codable
76-
distributed func _noop() {}
7774
}

Tests/DistributedActorsTests/DistributedReceptionistTests.swift

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,34 @@ final class DistributedReceptionistTests: ClusterSystemXCTestCase {
220220

221221
// ==== ----------------------------------------------------------------------------------------------------------------
222222

223-
// func test_receptionist_shouldNotRegisterTheSameRefTwice() throws {
224-
// let receptionist = SystemReceptionist(ref: try system._spawn("receptionist", self.receptionistBehavior))
225-
// let lookupProbe: ActorTestProbe<_Reception.Listing<_ActorRef<String>>> = self.testKit.makeTestProbe()
226-
//
227-
// let ref: _ActorRef<String> = try system._spawn(.anonymous, .receiveMessage { _ in .same })
228-
//
229-
// let key = _Reception.Key(_ActorRef<String>.self, id: "test")
230-
//
231-
// receptionist.checkIn(ref, with: key)
232-
// receptionist.checkIn(ref, with: key)
233-
//
234-
// receptionist.lookup(key, replyTo: lookupProbe.ref)
235-
//
236-
// let listing = try lookupProbe.expectMessage()
237-
//
238-
// listing.refs.count.shouldEqual(1)
239-
// }
240-
//
223+
func test_receptionist_shouldNotRegisterTheSameRefTwice() async throws {
224+
let ref = Forwarder(probe: nil, name: "D", actorSystem: system)
225+
226+
await system.receptionist.checkIn(ref, with: .forwarders)
227+
await system.receptionist.checkIn(ref, with: .forwarders)
228+
229+
let listing = await system.receptionist.lookup(.forwarders)
230+
231+
listing.count.shouldEqual(1)
232+
}
233+
234+
func test_receptionist_happyPath_lookup() async throws {
235+
let (first, second) = await self.setUpPair() { settings in
236+
settings.enabled = true
237+
}
238+
239+
let ref = Forwarder(probe: nil, name: "D", actorSystem: first)
240+
await first.receptionist.checkIn(ref, with: .forwarders)
241+
242+
first.cluster.join(node: second.cluster.uniqueNode.node)
243+
try await first.cluster.joined(node: second.cluster.uniqueNode, within: .seconds(30))
244+
245+
let listing = await second.receptionist.lookup(.forwarders)
246+
247+
listing.count.shouldEqual(1)
248+
listing.first!.id.shouldEqual(ref.id)
249+
}
250+
241251
// func test_receptionist_shouldRemoveAndAddNewSingletonRef() throws {
242252
// let receptionist = SystemReceptionist(ref: try system._spawn("receptionist", self.receptionistBehavior))
243253
// let lookupProbe: ActorTestProbe<_Reception.Listing<_ActorRef<String>>> = self.testKit.makeTestProbe()

0 commit comments

Comments
 (0)