Skip to content

Commit

Permalink
test: show lldb output when timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Nov 3, 2017
1 parent efaf023 commit 7d1d4a8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
74 changes: 47 additions & 27 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ else

exports.llnodePath = path.join(exports.buildDir, pluginName);

function SessionOutput(session, stream) {
function SessionOutput(session, stream, timeout) {
EventEmitter.call(this);
this.waiting = false;
this.waitQueue = [];

let buf = '';
this.timeout = timeout || 10000;

stream.on('data', (data) => {
buf += data;
Expand Down Expand Up @@ -72,48 +72,67 @@ SessionOutput.prototype._unqueueWait = function _unqueueWait() {
this.waitQueue.shift()();
};

SessionOutput.prototype.wait = function wait(regexp, callback) {
if (!this._queueWait(() => { this.wait(regexp, callback); }))
SessionOutput.prototype.timeoutAfter = function timeoutAfter(timeout) {
this.timeout = timeout;
}

SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
if (!this._queueWait(() => { this.wait(regexp, callback, allLines); }))
return;

const self = this;
this.on('line', function onLine(line) {
if (!regexp.test(line))
const lines = []; // save it in case it's an error

function onLine(line) {
lines.push(line);

if (!regexp.test(line)) {
return;
}

self.removeListener('line', onLine);
self._unqueueWait();
done = true;

callback(line);
});
callback(allLines ? lines : line);
}

let done = false;
let timePassed = 0;
const interval = 100;
// Get the stack out first
const check = setInterval(() => {
timePassed += interval;
if (done) {
clearInterval(check);
}

if (timePassed > self.timeout) {
self.removeListener('line', onLine);
self._unqueueWait();
const message = `Test timeout in ${this.timeout} ` +
`waiting for ${regexp}\n` +
`\n${'='.repeat(10)} lldb output ${'='.repeat(10)}\n` +
`\n${lines.join('\n')}` +
`\n${'='.repeat(30)}\n`;
throw new Error(message);
}
}, interval);

this.on('line', onLine);
};

SessionOutput.prototype.waitBreak = function waitBreak(callback) {
this.wait(/Process \d+ stopped/i, callback);
};

SessionOutput.prototype.linesUntil = function linesUntil(regexp, callback) {
if (!this._queueWait(() => { this.linesUntil(regexp, callback); }))
return;

const lines = [];
const self = this;
this.on('line', function onLine(line) {
lines.push(line);

if (!regexp.test(line))
return;

self.removeListener('line', onLine);
self._unqueueWait();

callback(lines);
});
this.wait(regexp, callback, true);
};


function Session(scenario) {
EventEmitter.call(this);
const timeout = parseInt(process.env.TEST_TIMEOUT) || 10000;

// lldb -- node scenario.js
this.lldb = spawn(process.env.TEST_LLDB_BINARY || 'lldb', [
Expand All @@ -133,13 +152,14 @@ function Session(scenario) {
this.lldb.stdin.write('run\n');

this.initialized = false;
this.stdout = new SessionOutput(this, this.lldb.stdout);
this.stderr = new SessionOutput(this, this.lldb.stderr);
this.stdout = new SessionOutput(this, this.lldb.stdout, timeout);
this.stderr = new SessionOutput(this, this.lldb.stderr, timeout);

// Map these methods to stdout for compatibility with legacy tests.
this.wait = SessionOutput.prototype.wait.bind(this.stdout);
this.waitBreak = SessionOutput.prototype.waitBreak.bind(this.stdout);
this.linesUntil = SessionOutput.prototype.linesUntil.bind(this.stdout);
this.timeoutAfter = SessionOutput.prototype.timeoutAfter.bind(this.stdout);
}
util.inherits(Session, EventEmitter);
exports.Session = Session;
Expand Down
1 change: 1 addition & 0 deletions test/scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tape('v8 findrefs and friends', (t) => {
t.timeoutAfter(90000);

const sess = common.Session.create('inspect-scenario.js');
sess.timeoutAfter(90000);

sess.waitBreak(() => {
sess.send(`process save-core ${common.core}`);
Expand Down

0 comments on commit 7d1d4a8

Please sign in to comment.