test: deflake test-tls-js-stream

`socket.destroy()` can destory the stream before the chunk to write
with `socket.end()` is actually sent. Furthermore `socket.destroy()`
destroys `p` and not the actual raw socket. As a result it is possible
that the connection is left open.

Remove `socket.destroy()` to ensure that the chunk is sent. Also use
`common.mustCall()` to ensure that the `'secureConnection'` and
`'secureConnect'` events are emitted exactly once.

PR-URL: https://github.com/nodejs/node/pull/27478
Fixes: https://github.com/nodejs/node/issues/26938
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
This commit is contained in:
Luigi Pinca 2019-04-29 17:27:25 +02:00
parent 9c43e7a10c
commit 8c4bd2af4f
2 changed files with 12 additions and 23 deletions

View File

@ -25,8 +25,6 @@ test-http2-client-upload-reject: PASS,FLAKY
[$system==linux]
[$system==macos]
# https://github.com/nodejs/node/issues/26938
test-tls-js-stream: PASS,FLAKY
[$arch==arm || $arch==arm64]
# https://github.com/nodejs/node/issues/26610

View File

@ -6,24 +6,19 @@ if (!common.hasCrypto)
const fixtures = require('../common/fixtures');
const assert = require('assert');
const net = require('net');
const stream = require('stream');
const tls = require('tls');
const connected = {
client: 0,
server: 0
};
const server = tls.createServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
}, function(c) {
}, common.mustCall(function(c) {
console.log('new client');
connected.server++;
c.resume();
c.end('ohai');
}).listen(0, function() {
})).listen(0, common.mustCall(function() {
const raw = net.connect(this.address().port);
let pending = false;
@ -32,6 +27,10 @@ const server = tls.createServer({
p._read();
});
raw.on('end', function() {
p.push(null);
});
const p = new stream.Duplex({
read: function read() {
pending = false;
@ -53,23 +52,15 @@ const server = tls.createServer({
const socket = tls.connect({
socket: p,
rejectUnauthorized: false
}, function() {
}, common.mustCall(function() {
console.log('client secure');
connected.client++;
socket.end('hello');
socket.resume();
socket.destroy();
});
socket.end('hello');
}));
socket.once('close', function() {
console.log('client close');
server.close();
});
});
process.once('exit', function() {
assert.strictEqual(connected.client, 1);
assert.strictEqual(connected.server, 1);
});
}));