Merge pull request 'Fix broken start()' (#2) from fix-start into master

Reviewed-on: https://codeberg.org/pzp/pzp-net/pulls/2
This commit is contained in:
Powersource 2024-05-15 16:24:22 +00:00
commit 2c9aa7384c
2 changed files with 11 additions and 1 deletions

View File

@ -91,7 +91,9 @@ function initNet(peer, config) {
async function start() {
await stats.loaded()
glue(infos, connections)
queueMicrotask(() => scheduler.start.bind(scheduler))
queueMicrotask(() => scheduler.start.bind(scheduler)((err) => {
if (err) console.error("pzp-net scheduler start failed:", err)
}))
}
function stop() {

View File

@ -62,6 +62,9 @@ test('Glueing together stats with connections', async (t) => {
while (FS.existsSync(statsJSONPath) === false) {
await p(setTimeout)(1)
}
await p(setTimeout)(2000)
const fileContents = FS.readFileSync(statsJSONPath, 'utf8')
const json = JSON.parse(fileContents)
assert.deepEqual(Object.keys(json), [TEST_ADDR])
@ -101,12 +104,17 @@ test('Glueing together stats with connections', async (t) => {
while (FS.existsSync(statsJSONPath) === false) {
await p(setTimeout)(1)
}
await p(setTimeout)(1000)
const fileContents = FS.readFileSync(statsJSONPath, 'utf8')
assert.equal(fileContents.length > 10, true, 'stats.json is not empty')
peer.net.forget(address)
await p(setTimeout)(200)
await p(setTimeout)(1000)
const entriesAfterForget = await p(peer.net.peers())(null)
assert.equal(entriesAfterForget.length, 0, 'there is no entry in peers()')