Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add fix's to let AIX run the test cleanly
  • Loading branch information
CurryKitten committed Mar 10, 2017
commit 63503f494dc1ccf37e75292d5296132314ea0344
60 changes: 31 additions & 29 deletions lib/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,38 +160,40 @@ class NodeInspector {
this.child.kill();
this.child = null;
}
return new Promise((resolve) => setTimeout(resolve, 2000));
}

run() {
this.killChild();
return this._runScript().then((child) => {
this.child = child;

let connectionAttempts = 0;
const attemptConnect = () => {
++connectionAttempts;
debuglog('connection attempt #%d', connectionAttempts);
this.stdout.write('.');
return this.client.connect()
.then(() => {
debuglog('connection established');
this.stdout.write(' ok');
}, (error) => {
debuglog('connect failed', error);
// If it's failed to connect 10 times then print failed message
if (connectionAttempts >= 10) {
this.stdout.write(' failed to connect, please retry\n');
process.exit(1);
}

return new Promise((resolve) => setTimeout(resolve, 500))
.then(attemptConnect);
});
};

const { host, port } = this.options;
this.print(`connecting to ${host}:${port} ..`, true);
return attemptConnect();
return this.killChild().then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't it be

return this.killChild().then(() => {
  return this._runScript();
}).then((child) => {
  // one indentation level less
});

?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, nested .thens are a slippery slope. I'd rather flatten this.

return this._runScript().then((child) => {
this.child = child;

let connectionAttempts = 0;
const attemptConnect = () => {
++connectionAttempts;
debuglog('connection attempt #%d', connectionAttempts);
this.stdout.write('.');
return this.client.connect()
.then(() => {
debuglog('connection established');
this.stdout.write(' ok');
}, (error) => {
debuglog('connect failed', error);
// If it's failed to connect 10 times then print failed message
if (connectionAttempts >= 10) {
this.stdout.write(' failed to connect, please retry\n');
process.exit(1);
}

return new Promise((resolve) => setTimeout(resolve, 500))
.then(attemptConnect);
});
};

const { host, port } = this.options;
this.print(`connecting to ${host}:${port} ..`, true);
return attemptConnect();
});
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ function createRepl(inspector) {
if (!newBreakpoints.length) return;
Promise.all(newBreakpoints).then((results) => {
print(`${results.length} breakpoints restored.`);
repl.displayPrompt();
});
}

Expand Down
13 changes: 9 additions & 4 deletions test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const { test } = require('tap');

const startCLI = require('./start-cli');

var brkLine = 1;
if (process.platform == 'aix') {
brkLine = 2;
}

test('break on (uncaught) exceptions', (t) => {
const script = Path.join('examples', 'exceptions.js');
const cli = startCLI([script]);
Expand All @@ -17,7 +22,7 @@ test('break on (uncaught) exceptions', (t) => {
return cli.waitFor(/break/)
.then(() => cli.waitForPrompt())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.output, `break in ${script}:${brkLine}`);
})
// making sure it will die by default:
.then(() => cli.command('c'))
Expand All @@ -26,7 +31,7 @@ test('break on (uncaught) exceptions', (t) => {
// Next run: With `breakOnException` it pauses in both places
.then(() => cli.stepCommand('r'))
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.output, `break in ${script}:${brkLine}`);
})
.then(() => cli.command('breakOnException'))
.then(() => cli.stepCommand('c'))
Expand All @@ -42,7 +47,7 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.command('breakOnUncaught'))
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.output, `break in ${script}:${brkLine}`);
})
.then(() => cli.stepCommand('c'))
.then(() => {
Expand All @@ -53,7 +58,7 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.command('breakOnNone'))
.then(() => cli.stepCommand('r'))
.then(() => {
t.match(cli.output, `break in ${script}:1`);
t.match(cli.output, `break in ${script}:${brkLine}`);
})
.then(() => cli.command('c'))
.then(() => cli.waitFor(/disconnect/))
Expand Down
4 changes: 2 additions & 2 deletions test/cli/start-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function startCLI(args) {
return output;
},

waitFor(pattern, timeout = 2000) {
waitFor(pattern, timeout = 5000) {
function checkPattern(str) {
if (Array.isArray(pattern)) {
return pattern.every((p) => p.test(str));
Expand Down Expand Up @@ -84,7 +84,7 @@ function startCLI(args) {
});
},

waitForPrompt(timeout = 2000) {
waitForPrompt(timeout = 5000) {
return this.waitFor(/>\s+$/, timeout);
},

Expand Down