mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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>
This commit is contained in:
@@ -11,12 +11,6 @@ var https = require('https');
|
||||
var net = require('net');
|
||||
var fs = require('fs');
|
||||
|
||||
var clientErrors = 0;
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.equal(clientErrors, 1);
|
||||
});
|
||||
|
||||
var options = {
|
||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
|
||||
@@ -25,15 +19,14 @@ var options = {
|
||||
|
||||
var server = https.createServer(options, common.fail);
|
||||
|
||||
server.on('clientError', function(err, conn) {
|
||||
server.on('clientError', common.mustCall(function(err, conn) {
|
||||
// Don't hesitate to update the asserts if the internal structure of
|
||||
// the cleartext object ever changes. We're checking that the https.Server
|
||||
// has closed the client connection.
|
||||
assert.equal(conn._secureEstablished, false);
|
||||
server.close();
|
||||
clientErrors++;
|
||||
conn.destroy();
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, function() {
|
||||
net.connect({ host: '127.0.0.1', port: this.address().port });
|
||||
|
||||
Reference in New Issue
Block a user