mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 17:25:20 +00:00
[codex] Refine BLE ingress fanout (#1280)
* 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>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user