Updates
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PGravityWell } = require('../index.js')
|
||||
|
||||
test('gravity-well: attract and drain', async (t) => {
|
||||
const g = new HyperP2PGravityWell()
|
||||
g.setWell('heavy-peer', 10)
|
||||
g.setWell('light-peer', 1)
|
||||
g.attract({ data: 'msg' })
|
||||
const batch = g.drain()
|
||||
t.is(batch.length, 1)
|
||||
await g.close()
|
||||
})
|
||||
|
||||
test('gravity-well: merge wells', async (t) => {
|
||||
const a = new HyperP2PGravityWell()
|
||||
const b = new HyperP2PGravityWell()
|
||||
a.setWell('p1', 5)
|
||||
b.mergeWells(a.toJSON())
|
||||
t.is(b._wells.get('p1').mass, 5)
|
||||
await a.close()
|
||||
await b.close()
|
||||
})
|
||||
test('hyper-p2p-gravity-well: close without leak', async (t) => {
|
||||
const m = new HyperP2PGravityWell()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
test('hyper-p2p-gravity-well: validation rejects invalid input', async (t) => {
|
||||
const m = new HyperP2PGravityWell()
|
||||
try {
|
||||
if (typeof m.addNeighbor === 'function') m.addNeighbor(null)
|
||||
else if (typeof m.buildCircuit === 'function') m.buildCircuit([])
|
||||
else if (typeof m.grant === 'function') m.grant(null, -1)
|
||||
else if (typeof m.enqueue === 'function') m.enqueue('bad', null)
|
||||
else if (typeof m.reportSample === 'function') m.reportSample(null, -1, -1)
|
||||
else if (typeof m.fanout === 'function') m.fanout(null, 0)
|
||||
else if (typeof m.probe === 'function') m.probe(null)
|
||||
else if (typeof m.resolve === 'function') m.resolve(null)
|
||||
else if (typeof m.acquire === 'function') m.acquire(null)
|
||||
else throw new Error('no validation hook')
|
||||
t.fail('expected throw')
|
||||
} catch (err) {
|
||||
t.ok(err instanceof Error)
|
||||
}
|
||||
await m.close()
|
||||
})
|
||||
Reference in New Issue
Block a user