fix(test): make SimulatedMeshTests storm bound deterministic (#1869)

* test(sim): track delivered frame counts per MessageType in SimulatedMesh

* fix(test): bound publicMessageRelaysAcrossLineTopologyWithinTTLBudget by .message frames
This commit is contained in:
Taksh Kothari authored and GitHub committed 2026-11-27 09:32:28 -10:00
1 parent 69a87bc3e0
commit 2691019689
2 files changed
+13 -3

No files matched your search

@@ -36,6 +36,13 @@ final class SimulatedMesh {
private var pendingDeliveries: [(from: Int, packet: BitchatPacket)] = []
/// Total (packet, receiving-node) deliveries pumped — the storm bound.
private(set) var deliveredFrameCount = 0
/// Per-`MessageType` delivery counts for deterministic storm bounds that
/// are unaffected by unrelated periodic announce/sync frames.
private(set) var deliveredFrameCountsByType: [UInt8: Int] = [:]
func deliveredFrameCount(ofType type: MessageType) -> Int {
deliveredFrameCountsByType[type.rawValue, default: 0]
}
private(set) var nodes: [Node] = []
private var neighbors: [Set<Int>] = []
@@ -176,6 +183,7 @@ final class SimulatedMesh {
for receiver in neighbors[from] {
for link in links(from: from, at: receiver) {
deliveredFrameCount += 1
deliveredFrameCountsByType[packet.type, default: 0] += 1
nodes[receiver].service._test_ingestFrame(packet, link: link)
}
}
@@ -129,7 +129,7 @@ struct SimulatedMeshTests {
if now == settled { break }
settled = now
}
let baseline = mesh.deliveredFrameCount
let baselineMessageFrames = mesh.deliveredFrameCount(ofType: .message)
let capture = TransportEventCapture()
c.service.eventDelegate = capture
@@ -143,8 +143,10 @@ struct SimulatedMeshTests {
let arrived = await capture.drainedPublicMessageCount(content: "hello line") == 1
#expect(arrived)
// Storm bound: a single public message across one relay hop must
// not multiply into more than a handful of frames.
#expect(mesh.deliveredFrameCount - baseline <= 12)
// not multiply into more than a handful of message frames. Measuring
// `.message` frames specifically prevents unrelated periodic announce
// or sync timers from flaking the bound on slow runners.
#expect(mesh.deliveredFrameCount(ofType: .message) - baselineMessageFrames <= 12)
}
@Test