Skip to content

Commit 82d28c5

Browse files
committed
test: make SessionOutput Promise tolerant
If a test case would use Promises for linesUntil, sometimes we would emit lines events while there was no listener attached to it. This commit changes SessionOutput to make it a little more resilient: now line events will only be emitted when the SessionOutput is waiting. When wait is called (via linesUntil, for example), it'll retrieve all lines (via line events) on the buffer until it reaches a line matching the regexp. If no lines match the regexp, we'll continue as before waiting for data from lldb and buffering it. PR-URL: #311 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent fd9d2b0 commit 82d28c5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/common.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ function SessionOutput(session, stream, timeout) {
4545
this.timeout = timeout || 10000;
4646
this.session = session;
4747

48-
stream.on('data', (data) => {
49-
buf += data;
50-
48+
this.flush = function flush() {
5149
for (;;) {
50+
// NOTE(mmarchini): don't emit line events while not waiting, otherwise
51+
// we might miss something.
52+
if (!this.waiting)
53+
break
54+
5255
let index = buf.indexOf('\n');
5356

5457
if (index === -1)
@@ -62,6 +65,11 @@ function SessionOutput(session, stream, timeout) {
6265
else
6366
this.emit('line', line);
6467
}
68+
}
69+
70+
stream.on('data', (data) => {
71+
buf += data;
72+
this.flush();
6573
});
6674

6775
// Ignore errors
@@ -129,6 +137,7 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
129137
}, this.timeout).unref();
130138

131139
this.on('line', onLine);
140+
this.flush();
132141
};
133142

134143
SessionOutput.prototype.waitBreak = function waitBreak(callback) {

0 commit comments

Comments
 (0)