mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:25:18 +00:00
* Refactor BLE transport event handling * Make image output paths unique * Keep queued Nostr read receipts alive * Refine BLE ingress fanout * Rediscover BLE service after invalidation * Extract BLE notification retry buffer * Extract BLE inbound write buffer * Extract BLE fragment assembly buffer * Tidy secure log handling from device run * Allow self-authored RSR ingress replies * Harden read receipt queue test timing --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
71 lines
1.9 KiB
Swift
71 lines
1.9 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import bitchat
|
|
|
|
struct BLEOutboundNotificationBufferTests {
|
|
@Test
|
|
func enqueueStoresNotificationsUntilTaken() {
|
|
var buffer = BLEOutboundNotificationBuffer<String>()
|
|
|
|
let result = buffer.enqueue(
|
|
data: Data([0x01]),
|
|
targets: ["central-1"],
|
|
capCount: 2
|
|
)
|
|
|
|
if case let .enqueued(count) = result {
|
|
#expect(count == 1)
|
|
} else {
|
|
Issue.record("Expected notification to be enqueued")
|
|
}
|
|
|
|
let pending = buffer.takeAll()
|
|
|
|
#expect(pending.count == 1)
|
|
#expect(pending.first?.data == Data([0x01]))
|
|
#expect(pending.first?.targets == ["central-1"])
|
|
#expect(buffer.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func enqueueRejectsWhenCapIsFull() {
|
|
var buffer = BLEOutboundNotificationBuffer<String>()
|
|
|
|
_ = buffer.enqueue(data: Data([0x01]), targets: nil, capCount: 1)
|
|
let result = buffer.enqueue(data: Data([0x02]), targets: nil, capCount: 1)
|
|
|
|
if case let .full(count) = result {
|
|
#expect(count == 1)
|
|
} else {
|
|
Issue.record("Expected full notification buffer")
|
|
}
|
|
|
|
#expect(buffer.count == 1)
|
|
}
|
|
|
|
@Test
|
|
func prependRestoresUnsentNotificationsAheadOfNewerItems() {
|
|
var buffer = BLEOutboundNotificationBuffer<String>()
|
|
let unsent = [
|
|
BLEPendingNotification(data: Data([0x01]), targets: ["old"])
|
|
]
|
|
|
|
_ = buffer.enqueue(data: Data([0x02]), targets: ["new"], capCount: 4)
|
|
buffer.prepend(unsent)
|
|
|
|
let pending = buffer.takeAll()
|
|
|
|
#expect(pending.map { Int($0.data.first ?? 0) } == [0x01, 0x02])
|
|
}
|
|
|
|
@Test
|
|
func removeAllClearsBufferedNotifications() {
|
|
var buffer = BLEOutboundNotificationBuffer<String>()
|
|
|
|
_ = buffer.enqueue(data: Data([0x01]), targets: nil, capCount: 4)
|
|
buffer.removeAll()
|
|
|
|
#expect(buffer.isEmpty)
|
|
}
|
|
}
|