Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
freeall committed Apr 10, 2024
1 parent 93abeb4 commit 5666093
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 17 additions & 5 deletions test/integration/fixtures/start-server.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
const DHT = require('../../../')
const repl = require('repl-swarm')
const fs = require('fs')

/*
This test is put into a fixture to make sure that each run is its own.
It will exit with 0 if able to start server, and 1 if there was an error when starting.
It will hang if, for some reason, `await server.listen()` never returns [TBC: this is the bug I am hunting]
*/

console.log('[server] i am alive')
log(`[server] i am alive. pid=${process.pid}`)

async function run () {
const node = new DHT()
const server = node.createServer(() => { })
const aliveInterval = setInterval(() => console.log('[server] i am alive'), 500)
repl({ data: { node, server } })
const aliveInterval = setInterval(() => log('[server] i am still alive'), 500)
aliveInterval.unref()
console.log('[server] ready to listen')
log('[server] ready to listen')
await server.listen()
console.log('[server] after await server.listen()')
log('[server] after await server.listen()')
}

run()
.then(() => {
log('[server] should do exit 0')
process.exit(0)
})
.catch(err => {
console.error(err)
log('[server] should do exit 1')
log(`[server] error: ${err.message}`)
error(err)
process.exit(1)
})

function log (str) {
// Not doing appendFileSync at the moment, to not change the timing too much
fs.appendFile('./log.log', `[${new Date().toISOString()}] [${process.pid}] ${str}\n`, () => { })
console.log(str)
}
12 changes: 8 additions & 4 deletions test/integration/server-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const { spawn } = require('child_process')
const test = require('brittle')
const repl = require('repl-swarm')

repl({ data: { i: 'am exposed in the repl' }, foo: 'anything in this map is exposed to the repl' })

const COUNT = 10000

Expand All @@ -26,8 +23,15 @@ test.skip(`Start a server ${COUNT} times`, { timeout: 0 }, async t => {
}
serverTest.fail(data.toString())
})
process.stderr.on('data', data => serverTest.fail(data.toString()))
process.stderr.on('data', data => {
if (data.toString().includes('repl-swarm')) {
console.log(data.toString().trim())
return
}
serverTest.fail(data.toString())
})
process.on('exit', (code) => {
console.log('exit', code)
if (code === 0) {
serverTest.pass(`Took ${Date.now() - startTime} ms`)
resolve()
Expand Down

0 comments on commit 5666093

Please sign in to comment.