Skip to content

Commit

Permalink
test: refactor test-net-GH-5504
Browse files Browse the repository at this point in the history
* Improve comments describing test.
* Remove unnecessary `common.noop`
* Remove confusing scoping of `c` identifier

PR-URL: #13025
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed May 20, 2017
1 parent 658741b commit 5254975
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions test/sequential/test-net-GH-5504.js
Expand Up @@ -22,11 +22,13 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');


// this test only fails with CentOS 6.3 using kernel version 2.6.32 // Ref: https://github.com/nodejs/node-v0.x-archive/issues/5504
// On other linuxes and darwin, the `read` call gets an ECONNRESET in //
// This test only fails with CentOS 6.3 using kernel version 2.6.32.
// On other Linuxes and macOS, the `read` call gets an ECONNRESET in
// that case. On sunos, the `write` call fails with EPIPE. // that case. On sunos, the `write` call fails with EPIPE.
// //
// However, old CentOS will occasionally send an EOF instead of a // However, old CentOS will occasionally send an EOF instead of an
// ECONNRESET or EPIPE when the client has been destroyed abruptly. // ECONNRESET or EPIPE when the client has been destroyed abruptly.
// //
// Make sure we don't keep trying to write or read more in that case. // Make sure we don't keep trying to write or read more in that case.
Expand Down Expand Up @@ -74,25 +76,24 @@ function parent() {
NODE_DEBUG: 'net' NODE_DEBUG: 'net'
}) })
}); });
let c;


wrap(s.stderr, process.stderr, 'SERVER 2>'); wrap(s.stderr, process.stderr, 'SERVER 2>');
wrap(s.stdout, process.stdout, 'SERVER 1>'); wrap(s.stdout, process.stdout, 'SERVER 1>');
s.on('exit', common.mustCall(common.noop)); s.on('exit', common.mustCall());


s.stdout.once('data', common.mustCall(function() { s.stdout.once('data', common.mustCall(function() {
c = spawn(node, [__filename, 'client']); const c = spawn(node, [__filename, 'client']);
wrap(c.stderr, process.stderr, 'CLIENT 2>'); wrap(c.stderr, process.stderr, 'CLIENT 2>');
wrap(c.stdout, process.stdout, 'CLIENT 1>'); wrap(c.stdout, process.stdout, 'CLIENT 1>');
c.on('exit', common.mustCall(common.noop)); c.on('exit', common.mustCall());
})); }));


function wrap(inp, out, w) { function wrap(inp, out, w) {
inp.setEncoding('utf8'); inp.setEncoding('utf8');
inp.on('data', function(c) { inp.on('data', function(chunk) {
c = c.trim(); chunk = chunk.trim();
if (!c) return; if (!chunk) return;
out.write(`${w}${c.split('\n').join(`\n${w}`)}\n`); out.write(`${w}${chunk.split('\n').join(`\n${w}`)}\n`);
}); });
} }
} }

0 comments on commit 5254975

Please sign in to comment.