Skip to content

Commit

Permalink
test: deflake test-tls-js-stream
Browse files Browse the repository at this point in the history
`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: #27478
Fixes: #26938
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
lpinca authored and targos committed May 9, 2019
1 parent ec642f1 commit a5dab9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
2 changes: 0 additions & 2 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 12 additions & 21 deletions test/parallel/test-tls-js-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
});
}));

0 comments on commit a5dab9e

Please sign in to comment.