Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor to const/let and common.mustCall #9934

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions test/parallel/test-tls-connect-simple.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const tls = require('tls');

var fs = require('fs');
const fs = require('fs');

var clientConnected = 0;
var serverConnected = 0;
var serverCloseCallbacks = 0;
var serverCloseEvents = 0;
let serverConnected = 0;

var options = {
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.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) {
server.close(function() {
++serverCloseCallbacks;
});
server.on('close', function() {
++serverCloseEvents;
});
server.close(common.mustCall(function() {}));
server.on('close', common.mustCall(function() {}));
}
});
}, 2));

server.listen(0, function() {
var client1 = tls.connect({
const client1options = {
port: this.address().port,
rejectUnauthorized: false
}, function() {
++clientConnected;
};
const client1 = tls.connect(client1options, common.mustCall(function() {
client1.end();
});
}));

var client2 = tls.connect({
const client2options = {
port: this.address().port,
rejectUnauthorized: false
});
client2.on('secureConnect', function() {
++clientConnected;
};
const client2 = tls.connect(client2options);
client2.on('secureConnect', common.mustCall(function() {
client2.end();
});
});

process.on('exit', function() {
assert.equal(clientConnected, 2);
assert.equal(serverConnected, 2);
assert.equal(serverCloseCallbacks, 1);
assert.equal(serverCloseEvents, 1);
}));
});