This commit is contained in:
Raven Scott
2026-05-20 22:28:59 -04:00
parent 341542f41b
commit e4400872c0
82 changed files with 2533 additions and 775 deletions
@@ -4,23 +4,38 @@ const { HyperP2PQosTopic, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PQosTopic)
t.ok(PROTOCOL)
t.is(PROTOCOL, 'qos-topic/v1')
})
test('basic operation', async (t) => {
test('higher qos delivered first on drain', async (t) => {
const m = new HyperP2PQosTopic()
m.put('k', 1); t.is(m.get('k'), 1)
const order = []
m.subscribe('c', (msg) => order.push(msg.payload), 0)
m._queues[0].push({ type: 'qos-publish', channel: 'c', payload: 'low', qos: 0, from: 'p' })
m._queues[2].push({ type: 'qos-publish', channel: 'c', payload: 'high', qos: 2, from: 'p' })
m._drain()
t.is(order[0], 'high')
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PQosTopic()
try { m.put(null, 1) } catch (e) { t.ok(e) }
try { m.publish('', 1) } catch (e) { t.ok(e) }
await m.close()
})
test('gossip delivery', async (t) => {
const m = new HyperP2PQosTopic()
let got = false
m.subscribe('x', () => { got = true })
m._onGossip({ type: 'qos-publish', channel: 'x', payload: 1, qos: 1, from: 'p' })
t.ok(got)
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PQosTopic()
t.ok(m.getStats().protocol)
m.publish('a', 1)
t.is(m.getStats().published, 1)
await m.close()
})