diff options
author | cjihrig <cjihrig@gmail.com> | 2016-07-15 15:43:24 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2016-07-18 17:14:16 -0400 |
commit | 04b4d15b396a7befea31dbfec89f69ff71dc71ca (patch) | |
tree | 7819010b9b687fb20328c04645e9ec64c25b9328 /test/sequential/test-net-GH-5504.js | |
parent | 59741a9beeb0ccaac6fc3247605bf090d36ad50e (diff) | |
download | android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.tar.gz android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.tar.bz2 android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.zip |
test: use mustCall() for simple flow tracking
Many of the tests use variables to track when callback functions
are invoked or events are emitted. These variables are then
asserted on process exit. This commit replaces this pattern in
straightforward cases with common.mustCall(). This makes the
tests easier to reason about, leads to a net reduction in lines
of code, and uncovered a few bugs in tests. This commit also
replaces some callbacks that should never be called with
common.fail().
PR-URL: https://github.com/nodejs/node/pull/7753
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/sequential/test-net-GH-5504.js')
-rw-r--r-- | test/sequential/test-net-GH-5504.js | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/test/sequential/test-net-GH-5504.js b/test/sequential/test-net-GH-5504.js index e760c26c29..c6e4e8e3d6 100644 --- a/test/sequential/test-net-GH-5504.js +++ b/test/sequential/test-net-GH-5504.js @@ -47,17 +47,6 @@ function client() { function parent() { var spawn = require('child_process').spawn; var node = process.execPath; - var assert = require('assert'); - var serverExited = false; - var clientExited = false; - var serverListened = false; - - process.on('exit', function() { - assert(serverExited); - assert(clientExited); - assert(serverListened); - console.log('ok'); - }); setTimeout(function() { if (s) s.kill(); @@ -76,21 +65,14 @@ function parent() { wrap(s.stderr, process.stderr, 'SERVER 2>'); wrap(s.stdout, process.stdout, 'SERVER 1>'); - s.on('exit', function(c) { - console.error('server exited', c); - serverExited = true; - }); + s.on('exit', common.mustCall(function(c) {})); - s.stdout.once('data', function() { - serverListened = true; + s.stdout.once('data', common.mustCall(function() { c = spawn(node, [__filename, 'client']); wrap(c.stderr, process.stderr, 'CLIENT 2>'); wrap(c.stdout, process.stdout, 'CLIENT 1>'); - c.on('exit', function(c) { - console.error('client exited', c); - clientExited = true; - }); - }); + c.on('exit', common.mustCall(function(c) {})); + })); function wrap(inp, out, w) { inp.setEncoding('utf8'); |