-
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
52 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const DHT = require('../../../') | ||
|
||
/* | ||
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] | ||
*/ | ||
|
||
async function run () { | ||
const node = new DHT() | ||
const server = node.createServer(() => { }) | ||
await server.listen() | ||
} | ||
|
||
run() | ||
.then(() => { | ||
process.exit(0) | ||
}) | ||
.catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { spawn } = require('child_process') | ||
const test = require('brittle') | ||
|
||
const COUNT = 10000 | ||
|
||
test.skip(`Start a server ${COUNT} times`, { timeout: 0 }, async t => { | ||
t.plan(COUNT) | ||
|
||
for (let i = 0; i < COUNT; i++) { | ||
const startTime = Date.now() | ||
await t.test(async serverTest => { | ||
serverTest.plan(1) | ||
|
||
await new Promise((resolve, reject) => { | ||
const process = spawn('node', ['fixtures/start-server.js', i]) | ||
process.stdout.on('data', data => serverTest.fail(data.toString())) | ||
process.stderr.on('data', data => serverTest.fail(data.toString())) | ||
process.on('exit', (code) => { | ||
if (code === 0) { | ||
serverTest.pass(`Took ${Date.now() - startTime} ms`) | ||
resolve() | ||
} else { | ||
serverTest.fail(`Test ${i} failed with code ${code}`) | ||
reject() | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
}) |