From a5dab9e85acc9b6c575e49dfdce2237ce284b97b Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 29 Apr 2019 17:27:25 +0200 Subject: [PATCH] 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 Reviewed-By: Sam Roberts Reviewed-By: Fedor Indutny --- test/parallel/parallel.status | 2 -- test/parallel/test-tls-js-stream.js | 33 +++++++++++------------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 33576ffc633a9f..c0a3f2a4c0000f 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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 diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js index 908f4c48876a56..298252962ba9cd 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; @@ -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); -}); +}));