Updates
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user