-
-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--on-port #145
--on-port #145
Changes from 11 commits
5371e0e
aa590d2
f456348
936a9a2
17e5c58
a05fc8b
50ac96e
c930369
0f309ad
efe1537
6b2025c
ab1212b
304826a
06270f6
1bb1f33
dc0cf5b
54be888
851ece7
9ef4270
f85b259
98a67de
0420249
56fb442
a98b679
515c5f9
0027720
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
const onListen = require('on-net-listen') | ||
const fs = require('fs') | ||
|
||
onListen(function (addr) { | ||
this.destroy() | ||
const port = Buffer.from(addr.port + '') | ||
fs.writeSync(3, port, 0, port.length) | ||
}) | ||
|
||
// `nitm` catches the SIGINT so we write it to a file descriptor instead | ||
const stream = fs.createReadStream('/', { fd: 3 }) | ||
process.on('exit', () => stream.close()) | ||
stream.once('data', (chunk) => { | ||
if (chunk.toString() === 'SIGINT') process.exit(0) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should unref the stream here? Just incase the server closes gracefully and we don't wanna keep it open. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm actually not sure how to do this, fs.ReadStream doesn't have an unref(). autocannon will send the SIGINT when it's done anyway so currently the process just keeps running for those additional seconds. Ideally the child process would exit when the server closes and autocannon would also stop, I guess? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const spawn = require('child_process').spawn | ||
const split = require('split2') | ||
const autocannon = require.resolve('../autocannon') | ||
const target = require.resolve('./targetProcess') | ||
|
||
const lines = [ | ||
/Running 1s test @ .*$/, | ||
/10 connections.*$/, | ||
/$/, | ||
/Stat.*Avg.*Stdev.*Max.*$/, | ||
/Latency \(ms\).*$/, | ||
/Req\/Sec.*$/, | ||
/Bytes\/Sec.*$/, | ||
/$/, | ||
// Ensure that there are more than 0 successful requests | ||
/[1-9]\d*.* requests in \d+s, .* read/ | ||
] | ||
|
||
t.plan(lines.length * 2) | ||
|
||
const child = spawn(autocannon, [ | ||
'-c', '10', | ||
'-d', '1', | ||
'--on-port', '/', | ||
'--', 'node', target | ||
], { | ||
cwd: __dirname, | ||
env: process.env, | ||
stdio: ['ignore', 'pipe', 'pipe'], | ||
detached: false | ||
}) | ||
|
||
t.tearDown(() => { | ||
child.kill() | ||
}) | ||
|
||
child | ||
.stderr | ||
.pipe(split()) | ||
.on('data', (line) => { | ||
const regexp = lines.shift() | ||
console.error(line) | ||
t.ok(regexp, 'we are expecting this line') | ||
t.ok(regexp.test(line), 'line matches ' + regexp) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const server = require('./helper').startServer() | ||
|
||
server.ref() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use NODE_PATH instead, as this will fail on windows with usernames with spaces in them (which lots of people have there).
Move detectPort.js to another folder, fx
./injects
and setprocess.env.NODE_PATH = path.join(__dirname, '/injects')
and use['-r', 'detectPort']
to work around that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took it from https://github.com/davidmarkclements/0x/blob/3611fc7f7c04ee741daeda33c972bb26cd7bdd0b/platform/v8.js#L34, so we should also change it there then. Does windows not support quoted arguments? 😱