36 lines
915 B
JavaScript
36 lines
915 B
JavaScript
require('bare-process/global')
|
|
const test = require('brittle')
|
|
const { HyperP2PHealthProbe, PROTOCOL } = require('../index.js')
|
|
|
|
test('exports', (t) => {
|
|
t.ok(HyperP2PHealthProbe)
|
|
t.is(PROTOCOL, 'health-probe/v1')
|
|
})
|
|
|
|
test('report and query', async (t) => {
|
|
const m = new HyperP2PHealthProbe()
|
|
m.report('peer-a', { ok: true, rttMs: 12 })
|
|
t.ok(m.get('peer-a').ok)
|
|
t.is(m.healthyPeers().length, 1)
|
|
await m.close()
|
|
})
|
|
|
|
test('validation', async (t) => {
|
|
const m = new HyperP2PHealthProbe()
|
|
try { m.report('', {}) } catch (e) { t.ok(e) }
|
|
await m.close()
|
|
})
|
|
|
|
test('remote report', async (t) => {
|
|
const m = new HyperP2PHealthProbe()
|
|
m._onGossip({ type: 'health', entry: { peerId: 'b', ok: false, at: 1 } })
|
|
t.is(m.get('b').ok, false)
|
|
await m.close()
|
|
})
|
|
|
|
test('getStats', async (t) => {
|
|
const m = new HyperP2PHealthProbe()
|
|
t.is(m.getStats().protocol, 'health-probe/v1')
|
|
await m.close()
|
|
})
|