From 89ff7ddce8b8cb7dcec688b14c395fc91ae9a4b7 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 8 Dec 2015 13:36:38 +0100 Subject: [PATCH 1/2] test: fix tls-inception Make sure all the data is read before checking its validity. Remove `gotHello` variable and just check that the ssl `end` event is received. Remove unused variables. --- test/parallel/test-tls-inception.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-tls-inception.js b/test/parallel/test-tls-inception.js index 12b9f95facc686..bf8688fdd29418 100644 --- a/test/parallel/test-tls-inception.js +++ b/test/parallel/test-tls-inception.js @@ -12,8 +12,7 @@ var fs = require('fs'); var path = require('path'); var net = require('net'); -var options, a, b, portA, portB; -var gotHello = false; +var options, a, b; var body = new Buffer(4000).fill('A'); @@ -43,10 +42,6 @@ b = tls.createServer(options, function(socket) { socket.end(body); }); -process.on('exit', function() { - assert(gotHello); -}); - a.listen(common.PORT, function() { b.listen(common.PORT + 1, function() { options = { @@ -62,15 +57,14 @@ a.listen(common.PORT, function() { }); ssl.setEncoding('utf8'); var buf = ''; - ssl.once('data', function(data) { + ssl.on('data', function(data) { buf += data; - gotHello = true; }); - ssl.on('end', function() { + ssl.on('end', common.mustCall(function() { assert.equal(buf, body); ssl.end(); a.close(); b.close(); - }); + })); }); }); From 432a86eb88f69e8d94253087bfd707cfce73828c Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 8 Dec 2015 14:57:22 +0100 Subject: [PATCH 2/2] test: fix tls-inception flakiness When sending a very large buffer (400000 bytes) the test fails due to the client socket from the `a` server erroring with `ECONNRESET`. There's a race condition between the closing of this socket and the `ssl` socket closing on the other side of the connection. To improve things, destroy the socket as soon as possible: in the `end` event of the `dest` socket. --- test/parallel/test-tls-inception.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-tls-inception.js b/test/parallel/test-tls-inception.js index bf8688fdd29418..8946f52bdd63d4 100644 --- a/test/parallel/test-tls-inception.js +++ b/test/parallel/test-tls-inception.js @@ -14,7 +14,7 @@ var net = require('net'); var options, a, b; -var body = new Buffer(4000).fill('A'); +var body = new Buffer(400000).fill('A'); options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), @@ -32,7 +32,7 @@ a = tls.createServer(options, function(socket) { dest.pipe(socket); socket.pipe(dest); - dest.on('close', function() { + dest.on('end', function() { socket.destroy(); }); });