Skip to content

Instantly share code, notes, and snippets.

@jelmd
Created December 15, 2015 21:59
Show Gist options
  • Save jelmd/c1c1cd7d1c49a3385adf to your computer and use it in GitHub Desktop.
Save jelmd/c1c1cd7d1c49a3385adf to your computer and use it in GitHub Desktop.
--- ./test/parallel/test-debug-signal-cluster.js.orig Thu Oct 29 13:22:06 2015
+++ ./test/parallel/test-debug-signal-cluster.js Thu Nov 12 04:08:31 2015
@@ -14,34 +14,48 @@
var waitingForDebuggers = false;
var pids = null;
+var n = 0;
-child.stderr.on('data', function(data) {
- var lines = data.toString().replace(/\r/g, '').trim().split('\n');
+var expectedLines = [
+ 'Starting debugger agent.',
+ 'Debugger listening on port ' + (port + 0),
+ 'Starting debugger agent.',
+ 'Debugger listening on port ' + (port + 1),
+ 'Starting debugger agent.',
+ 'Debugger listening on port ' + (port + 2)
+];
- lines.forEach(function(line) {
- console.log('> ' + line);
+var rcvdTxt = '';
+var expectedTxt = '';
+for (var i = 0; i < expectedLines.length; i++)
+ expectedTxt += expectedLines[i];
- if (line === 'all workers are running') {
- child.on('message', function(msg) {
- if (msg.type !== 'pids')
- return;
+child.stderr.on('data', function(data) {
+ var d = data.toString().trim();
+ console.log(n + '> ' + d);
+ n++;
- pids = msg.pids;
- console.error('got pids %j', pids);
+ if (waitingForDebuggers) {
+ // hopefully another write just intercepts the trailing '\n', only ..
+ rcvdTxt += d.replace(/[\r\n]/g, '');
+ } else if (d.indexOf('all workers are running') != -1) {
+ child.on('message', function(msg) {
+ if (msg.type !== 'pids')
+ return;
- waitingForDebuggers = true;
- process._debugProcess(child.pid);
- });
+ pids = msg.pids;
+ console.error('got pids %j', pids);
- child.send({
- type: 'getpids'
- });
- } else if (waitingForDebuggers) {
- outputLines.push(line);
- }
+ waitingForDebuggers = true;
+ process._debugProcess(child.pid);
+ });
- });
- if (outputLines.length >= expectedLines.length)
+ child.send({
+ type: 'getpids'
+ });
+ }
+
+ if (rcvdTxt.length >= expectedTxt.length)
onNoMoreLines();
});
@@ -62,23 +76,13 @@
});
});
-var expectedLines = [
- 'Starting debugger agent.',
- 'Debugger listening on port ' + (port + 0),
- 'Starting debugger agent.',
- 'Debugger listening on port ' + (port + 1),
- 'Starting debugger agent.',
- 'Debugger listening on port ' + (port + 2),
-];
function assertOutputLines() {
- // Do not assume any particular order of output messages,
- // since workers can take different amout of time to
- // start up
- outputLines.sort();
- expectedLines.sort();
-
- assert.equal(outputLines.length, expectedLines.length);
- for (var i = 0; i < expectedLines.length; i++)
- assert.equal(outputLines[i], expectedLines[i]);
+ assert(rcvdTxt.length >= expectedTxt.length);
+ for (var i = 0; i < expectedLines.length; i++) {
+ var k = rcvdTxt.indexOf(expectedLines[i]);
+ assert(k >= 0, 'Message "' + expectedLines[i] + '" (' + i + ') not found.');
+ rcvdTxt = rcvdTxt.substr(0,k) + rcvdTxt.substr(k + expectedLines[i].length);
+ }
+ //console.error("Remaining text: '" + rcvdTxt + "'");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment