Skip to content

Commit fd242f4

Browse files
Make "is map entry tombstoned" check referenced object per RTLM14c
Based on spec referenced in 040987b; same comment re testing applies too.
1 parent 448b53d commit fd242f4

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ internal final class InternalDefaultLiveMap: Sendable {
131131
return convertEntryToLiveMapValue(entry, delegate: delegate)
132132
}
133133

134-
internal func size(coreSDK: CoreSDK) throws(ARTErrorInfo) -> Int {
134+
internal func size(coreSDK: CoreSDK, delegate: LiveMapObjectPoolDelegate) throws(ARTErrorInfo) -> Int {
135135
// RTLM10c: If the channel is in the DETACHED or FAILED state, the library should throw an ErrorInfo error with statusCode 400 and code 90001
136136
try coreSDK.validateChannelState(notIn: [.detached, .failed], operationDescription: "LiveMap.size")
137137

138138
return mutex.withLock {
139139
// RTLM10d: Returns the number of non-tombstoned entries (per RTLM14) in the internal data map
140140
mutableState.data.values.count { entry in
141-
!Self.isEntryTombstoned(entry)
141+
!Self.isEntryTombstoned(entry, delegate: delegate)
142142
}
143143
}
144144
}
@@ -152,7 +152,7 @@ internal final class InternalDefaultLiveMap: Sendable {
152152
// RTLM11d1: Pairs with tombstoned entries (per RTLM14) are not returned
153153
var result: [(key: String, value: InternalLiveMapValue)] = []
154154

155-
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry) {
155+
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry, delegate: delegate) {
156156
// Convert entry to LiveMapValue using the same logic as get(key:)
157157
if let value = convertEntryToLiveMapValue(entry, delegate: delegate) {
158158
result.append((key: key, value: value))
@@ -758,9 +758,21 @@ internal final class InternalDefaultLiveMap: Sendable {
758758
// MARK: - Helper Methods
759759

760760
/// Returns whether a map entry should be considered tombstoned, per the check described in RTLM14.
761-
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry) -> Bool {
762-
// RTLM14a, RTLM14b
763-
entry.tombstone == true
761+
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry, delegate: LiveMapObjectPoolDelegate) -> Bool {
762+
// RTLM14a
763+
if entry.tombstone {
764+
return true
765+
}
766+
767+
// RTLM14c
768+
if let objectId = entry.data.objectId {
769+
if let poolEntry = delegate.getObjectFromPool(id: objectId), poolEntry.isTombstone {
770+
return false
771+
}
772+
}
773+
774+
// RTLM14b
775+
return false
764776
}
765777

766778
/// Converts an InternalObjectsMapEntry to LiveMapValue using the same logic as get(key:)

Sources/AblyLiveObjects/Public/Public Proxy Objects/PublicDefaultLiveMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal final class PublicDefaultLiveMap: LiveMap {
3434

3535
internal var size: Int {
3636
get throws(ARTErrorInfo) {
37-
try proxied.size(coreSDK: coreSDK)
37+
try proxied.size(coreSDK: coreSDK, delegate: delegate)
3838
}
3939
}
4040

Tests/AblyLiveObjectsTests/InternalDefaultLiveMapTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct InternalDefaultLiveMapTests {
284284

285285
// Define actions to test
286286
let actions: [(String, () throws -> Any)] = [
287-
("size", { try map.size(coreSDK: coreSDK) }),
287+
("size", { try map.size(coreSDK: coreSDK, delegate: delegate) }),
288288
("entries", { try map.entries(coreSDK: coreSDK, delegate: delegate) }),
289289
("keys", { try map.keys(coreSDK: coreSDK, delegate: delegate) }),
290290
("values", { try map.values(coreSDK: coreSDK, delegate: delegate) }),
@@ -330,7 +330,7 @@ struct InternalDefaultLiveMapTests {
330330
)
331331

332332
// Test size - should only count non-tombstoned entries
333-
let size = try map.size(coreSDK: coreSDK)
333+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
334334
#expect(size == 1)
335335

336336
// Test entries - should only return non-tombstoned entries
@@ -372,7 +372,7 @@ struct InternalDefaultLiveMapTests {
372372
clock: MockSimpleClock(),
373373
)
374374

375-
let size = try map.size(coreSDK: coreSDK)
375+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
376376
let entries = try map.entries(coreSDK: coreSDK, delegate: delegate)
377377
let keys = try map.keys(coreSDK: coreSDK, delegate: delegate)
378378
let values = try map.values(coreSDK: coreSDK, delegate: delegate)
@@ -422,7 +422,7 @@ struct InternalDefaultLiveMapTests {
422422
clock: MockSimpleClock(),
423423
)
424424

425-
let size = try map.size(coreSDK: coreSDK)
425+
let size = try map.size(coreSDK: coreSDK, delegate: delegate)
426426
let entries = try map.entries(coreSDK: coreSDK, delegate: delegate)
427427
let keys = try map.keys(coreSDK: coreSDK, delegate: delegate)
428428
let values = try map.values(coreSDK: coreSDK, delegate: delegate)

0 commit comments

Comments
 (0)