From c9e918bcaca1120e8d55e62ac50787c031f92538 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 29 Apr 2019 17:27:25 +0200 Subject: [PATCH 1/2] 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. Fixes: https://github.com/nodejs/node/issues/26938 --- test/parallel/parallel.status | 2 -- test/parallel/test-tls-js-stream.js | 29 ++++++++--------------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index e234c1b256c942..cf208c166a8696 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -23,8 +23,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 diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js index 908f4c48876a56..4090c9f0187238 100644 --- a/test/parallel/test-tls-js-stream.js +++ b/test/parallel/test-tls-js-stream.js @@ -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; @@ -53,23 +48,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); -}); +})); From 432f39a929a0a5616a7839d1ae3c11fa85766618 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 4 May 2019 12:08:31 +0200 Subject: [PATCH 2/2] fixup! test: deflake test-tls-js-stream --- test/parallel/test-tls-js-stream.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js index 4090c9f0187238..298252962ba9cd 100644 --- a/test/parallel/test-tls-js-stream.js +++ b/test/parallel/test-tls-js-stream.js @@ -27,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;