mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-11-29 08:29:22 +00:00
* Deduplicate MessageOutboxStore recovery state machine and MessageRouter loops * Unify NostrInboundPipeline and GeohashSubscriptionManager duplicate paths * Remove dead notifyUIChanged() plumbing and retire BitchatDelegate * Deduplicate BLEService core paths, link state types, and gossip sync * Deduplicate NoiseProtocol DH operations, key loading, and rate limiter * Consolidate AppSupport JSON stores, BoundedCache, Keychain upserts, and Favorites load * Add shared TLVWriter/TLVReader in BitFoundation and migrate protocol codecs * Deduplicate cross-platform views, utilities, and audio session RAII * Address PR 1904 review: bound BoundedCache hot-key history and clean Periphery warnings --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
28 lines
891 B
Swift
28 lines
891 B
Swift
import Foundation
|
|
import Testing
|
|
@testable import bitchat
|
|
|
|
struct BoundedCacheTests {
|
|
@Test func repeatedSingleKeyRefreshesKeepHistoryBounded() {
|
|
var cache = BoundedCache<String, Int>(capacity: 64)
|
|
for index in 0..<10_000 {
|
|
cache.set("hot", value: index)
|
|
}
|
|
#expect(cache.count == 1)
|
|
#expect(cache.value(for: "hot") == 9_999)
|
|
#expect(cache.historyCountForTesting <= 128)
|
|
}
|
|
|
|
@Test func repeatedHotKeyRefreshWithColdFrontEntryCompactsHistory() {
|
|
var cache = BoundedCache<String, Int>(capacity: 64)
|
|
cache.set("cold", value: 0)
|
|
for index in 1...10_000 {
|
|
cache.set("hot", value: index)
|
|
}
|
|
#expect(cache.count == 2)
|
|
#expect(cache.value(for: "cold") == 0)
|
|
#expect(cache.value(for: "hot") == 10_000)
|
|
#expect(cache.historyCountForTesting <= 128)
|
|
}
|
|
}
|