Skip to content

src: check whether inspector is doing io #13504

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

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3059,8 +3059,8 @@ static void DebugPortGetter(Local<Name> property,
#if HAVE_INSPECTOR
if (port == 0) {
Environment* env = Environment::GetCurrent(info);
if (env->inspector_agent()->IsStarted())
port = env->inspector_agent()->io()->port();
if (auto io = env->inspector_agent()->io())
port = io->port();
}
#endif // HAVE_INSPECTOR
info.GetReturnValue().Set(port);
Expand Down
9 changes: 7 additions & 2 deletions test/inspector/test-inspector-port-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assert = require('assert');
const { URL } = require('url');
const { spawn } = require('child_process');

function test(arg) {
function test(arg, port = '') {
const args = [arg, '-p', 'process.debugPort'];
const proc = spawn(process.execPath, args);
proc.stdout.setEncoding('utf8');
Expand All @@ -18,7 +18,6 @@ function test(arg) {
proc.stderr.on('data', (data) => stderr += data);
proc.stdout.on('close', assert.ifError);
proc.stderr.on('close', assert.ifError);
let port = '';
proc.stderr.on('data', () => {
if (!stderr.includes('\n')) return;
assert(/Debugger listening on (.+)/.test(stderr));
Expand Down Expand Up @@ -46,3 +45,9 @@ test('--inspect=localhost:0');
test('--inspect-brk=0');
test('--inspect-brk=127.0.0.1:0');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugeneo can we have some of these in #13478?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tests there

test('--inspect-brk=localhost:0');

// In these cases, the inspector doesn't listen, so an ephemeral port is not
// allocated and the expected value of `process.debugPort` is `0`.
test('--inspect-port=0', '0');
test('--inspect-port=127.0.0.1:0', '0');
test('--inspect-port=localhost:0', '0');