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/parallel/test-tls-securepair-server.js | |
parent | 59741a9beeb0ccaac6fc3247605bf090d36ad50e (diff) | |
download | node-new-04b4d15b396a7befea31dbfec89f69ff71dc71ca.tar.gz |
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/parallel/test-tls-securepair-server.js')
-rw-r--r-- | test/parallel/test-tls-securepair-server.js | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/test/parallel/test-tls-securepair-server.js b/test/parallel/test-tls-securepair-server.js index e6d01b7048..24ac2177c5 100644 --- a/test/parallel/test-tls-securepair-server.js +++ b/test/parallel/test-tls-securepair-server.js @@ -13,7 +13,6 @@ var net = require('net'); var fs = require('fs'); var spawn = require('child_process').spawn; -var connections = 0; var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); @@ -21,8 +20,7 @@ function log(a) { console.error('***server*** ' + a); } -var server = net.createServer(function(socket) { - connections++; +var server = net.createServer(common.mustCall(function(socket) { log('connection fd=' + socket.fd); var sslcontext = tls.createSecureContext({key: key, cert: cert}); sslcontext.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); @@ -84,14 +82,13 @@ var server = net.createServer(function(socket) { log(err.stack); socket.destroy(); }); -}); +})); var gotHello = false; var sentWorld = false; var gotWorld = false; -var opensslExitCode = -1; -server.listen(0, function() { +server.listen(0, common.mustCall(function() { // To test use: openssl s_client -connect localhost:8000 var args = ['s_client', '-connect', `127.0.0.1:${this.address().port}`]; @@ -123,16 +120,14 @@ server.listen(0, function() { client.stdout.pipe(process.stdout, { end: false }); - client.on('exit', function(code) { - opensslExitCode = code; + client.on('exit', common.mustCall(function(code) { + assert.strictEqual(0, code); server.close(); - }); -}); + })); +})); process.on('exit', function() { - assert.equal(1, connections); assert.ok(gotHello); assert.ok(sentWorld); assert.ok(gotWorld); - assert.equal(0, opensslExitCode); }); |