mirror of https://github.com/lukechilds/node.git
Browse Source
refactor var -> const/let refactor process.on('exit') into common.mustCall PR-URL: https://github.com/nodejs/node/pull/9934 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>v4.x
committed by
Myles Borins
1 changed files with 18 additions and 33 deletions
@ -1,58 +1,43 @@ |
|||||
'use strict'; |
'use strict'; |
||||
var common = require('../common'); |
const common = require('../common'); |
||||
var assert = require('assert'); |
|
||||
|
|
||||
if (!common.hasCrypto) { |
if (!common.hasCrypto) { |
||||
common.skip('missing crypto'); |
common.skip('missing crypto'); |
||||
return; |
return; |
||||
} |
} |
||||
var tls = require('tls'); |
const tls = require('tls'); |
||||
|
|
||||
var fs = require('fs'); |
const fs = require('fs'); |
||||
|
|
||||
var clientConnected = 0; |
let serverConnected = 0; |
||||
var serverConnected = 0; |
|
||||
var serverCloseCallbacks = 0; |
|
||||
var serverCloseEvents = 0; |
|
||||
|
|
||||
var options = { |
const options = { |
||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), |
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), |
||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') |
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') |
||||
}; |
}; |
||||
|
|
||||
var server = tls.Server(options, function(socket) { |
const server = tls.Server(options, common.mustCall(function(socket) { |
||||
if (++serverConnected === 2) { |
if (++serverConnected === 2) { |
||||
server.close(function() { |
server.close(common.mustCall(function() {})); |
||||
++serverCloseCallbacks; |
server.on('close', common.mustCall(function() {})); |
||||
}); |
|
||||
server.on('close', function() { |
|
||||
++serverCloseEvents; |
|
||||
}); |
|
||||
} |
} |
||||
}); |
}, 2)); |
||||
|
|
||||
server.listen(0, function() { |
server.listen(0, function() { |
||||
var client1 = tls.connect({ |
const client1options = { |
||||
port: this.address().port, |
port: this.address().port, |
||||
rejectUnauthorized: false |
rejectUnauthorized: false |
||||
}, function() { |
}; |
||||
++clientConnected; |
const client1 = tls.connect(client1options, common.mustCall(function() { |
||||
client1.end(); |
client1.end(); |
||||
}); |
})); |
||||
|
|
||||
var client2 = tls.connect({ |
const client2options = { |
||||
port: this.address().port, |
port: this.address().port, |
||||
rejectUnauthorized: false |
rejectUnauthorized: false |
||||
}); |
}; |
||||
client2.on('secureConnect', function() { |
const client2 = tls.connect(client2options); |
||||
++clientConnected; |
client2.on('secureConnect', common.mustCall(function() { |
||||
client2.end(); |
client2.end(); |
||||
}); |
})); |
||||
}); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
assert.equal(clientConnected, 2); |
|
||||
assert.equal(serverConnected, 2); |
|
||||
assert.equal(serverCloseCallbacks, 1); |
|
||||
assert.equal(serverCloseEvents, 1); |
|
||||
}); |
}); |
||||
|
Loading…
Reference in new issue