-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters