mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
var tls = require('tls');
|
|
|
|
var fs = require('fs');
|
|
|
|
var dir = common.fixturesDir;
|
|
var options = { key: fs.readFileSync(dir + '/test_key.pem'),
|
|
cert: fs.readFileSync(dir + '/test_cert.pem'),
|
|
ca: [ fs.readFileSync(dir + '/test_ca.pem') ] };
|
|
|
|
var writes = [
|
|
'some server data',
|
|
'and a separate packet',
|
|
'and one more',
|
|
];
|
|
var receivedWrites = 0;
|
|
|
|
var server = tls.createServer(options, function(c) {
|
|
writes.forEach(function(str) {
|
|
c.write(str);
|
|
});
|
|
}).listen(0, function() {
|
|
const connectOpts = { rejectUnauthorized: false };
|
|
var c = tls.connect(this.address().port, connectOpts, function() {
|
|
c.write('some client data');
|
|
c.on('readable', function() {
|
|
var data = c.read();
|
|
if (data === null)
|
|
return;
|
|
|
|
data = data.toString();
|
|
while (data.length !== 0) {
|
|
assert.strictEqual(data.indexOf(writes[receivedWrites]), 0);
|
|
data = data.slice(writes[receivedWrites].length);
|
|
|
|
if (++receivedWrites === writes.length) {
|
|
c.end();
|
|
server.close();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(receivedWrites, writes.length);
|
|
});
|