Skip to content

Commit 8231989

Browse files
committed
test: show lldb output when timing out
1 parent efaf023 commit 8231989

2 files changed

Lines changed: 47 additions & 27 deletions

File tree

test/common.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ else
2323

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

26-
function SessionOutput(session, stream) {
26+
function SessionOutput(session, stream, timeout) {
2727
EventEmitter.call(this);
2828
this.waiting = false;
2929
this.waitQueue = [];
30-
3130
let buf = '';
31+
this.timeout = timeout || 10000;
3232

3333
stream.on('data', (data) => {
3434
buf += data;
@@ -72,48 +72,66 @@ SessionOutput.prototype._unqueueWait = function _unqueueWait() {
7272
this.waitQueue.shift()();
7373
};
7474

75-
SessionOutput.prototype.wait = function wait(regexp, callback) {
76-
if (!this._queueWait(() => { this.wait(regexp, callback); }))
75+
SessionOutput.prototype.timeoutAfter = function timeoutAfter(timeout) {
76+
this.timeout = timeout;
77+
}
78+
79+
SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
80+
if (!this._queueWait(() => { this.wait(regexp, callback, allLines); }))
7781
return;
7882

7983
const self = this;
80-
this.on('line', function onLine(line) {
81-
if (!regexp.test(line))
84+
const lines = [];
85+
86+
function onLine(line) {
87+
lines.push(line);
88+
89+
if (!regexp.test(line)) {
8290
return;
91+
}
8392

8493
self.removeListener('line', onLine);
8594
self._unqueueWait();
95+
done = true;
8696

87-
callback(line);
88-
});
97+
callback(allLines ? lines : line);
98+
}
99+
100+
let done = false;
101+
let timePassed = 0;
102+
const interval = 100;
103+
const check = setInterval(() => {
104+
timePassed += interval;
105+
if (done) {
106+
clearInterval(check);
107+
}
108+
109+
if (timePassed > self.timeout) {
110+
self.removeListener('line', onLine);
111+
self._unqueueWait();
112+
const message = `Test timeout in ${this.timeout} ` +
113+
`waiting for ${regexp}\n` +
114+
`\n${'='.repeat(10)} lldb output ${'='.repeat(10)}\n` +
115+
`\n${lines.join('\n')}` +
116+
`\n${'='.repeat(30)}\n`;
117+
throw new Error(message);
118+
}
119+
}, interval);
120+
121+
this.on('line', onLine);
89122
};
90123

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

95128
SessionOutput.prototype.linesUntil = function linesUntil(regexp, callback) {
96-
if (!this._queueWait(() => { this.linesUntil(regexp, callback); }))
97-
return;
98-
99-
const lines = [];
100-
const self = this;
101-
this.on('line', function onLine(line) {
102-
lines.push(line);
103-
104-
if (!regexp.test(line))
105-
return;
106-
107-
self.removeListener('line', onLine);
108-
self._unqueueWait();
109-
110-
callback(lines);
111-
});
129+
this.wait(regexp, callback, true);
112130
};
113131

114-
115132
function Session(scenario) {
116133
EventEmitter.call(this);
134+
const timeout = parseInt(process.env.TEST_TIMEOUT) || 10000;
117135

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

135153
this.initialized = false;
136-
this.stdout = new SessionOutput(this, this.lldb.stdout);
137-
this.stderr = new SessionOutput(this, this.lldb.stderr);
154+
this.stdout = new SessionOutput(this, this.lldb.stdout, timeout);
155+
this.stderr = new SessionOutput(this, this.lldb.stderr, timeout);
138156

139157
// Map these methods to stdout for compatibility with legacy tests.
140158
this.wait = SessionOutput.prototype.wait.bind(this.stdout);
141159
this.waitBreak = SessionOutput.prototype.waitBreak.bind(this.stdout);
142160
this.linesUntil = SessionOutput.prototype.linesUntil.bind(this.stdout);
161+
this.timeoutAfter = SessionOutput.prototype.timeoutAfter.bind(this.stdout);
143162
}
144163
util.inherits(Session, EventEmitter);
145164
exports.Session = Session;

test/scan-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tape('v8 findrefs and friends', (t) => {
1212
t.timeoutAfter(90000);
1313

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

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

0 commit comments

Comments
 (0)