Files
modules/measurement-rate-control/hyper-p2p-histogram-gossip/test/test.js
T
2026-05-20 22:56:32 -04:00

39 lines
1.1 KiB
JavaScript

require('bare-process/global')
const test = require('brittle')
const { HyperP2PHistogramGossip, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PHistogramGossip)
t.is(PROTOCOL, 'histogram-gossip/v1')
})
test('observe percentile', async (t) => {
const m = new HyperP2PHistogramGossip()
m.observe('latency', 10)
m.observe('latency', 20)
m.observe('latency', 30)
t.ok(typeof m.percentile('latency', 50) === 'number')
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PHistogramGossip()
try { m.observe('', 1) } catch (e) { t.ok(e) }
await m.close()
})
test('remote gossip', async (t) => {
const m = new HyperP2PHistogramGossip()
m._onGossip({ type: 'histogram-buckets', metric: 'cpu', min: 0, max: 10, counts: [1, 2, 0, 0, 0, 0, 0, 0, 0, 0] })
t.ok(m.snapshot('cpu').total >= 3)
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PHistogramGossip()
m.observe('x', 1)
t.is(m.getStats().protocol, 'histogram-gossip/v1')
t.is(m.getStats().observed, 1)
await m.close()
})