test: fix tls-no-rsa-key flakiness
authorSantiago Gimeno <santiago.gimeno@gmail.com>
Thu, 26 Nov 2015 21:58:51 +0000 (22:58 +0100)
committerMyles Borins <mborins@us.ibm.com>
Mon, 15 Feb 2016 19:30:23 +0000 (11:30 -0800)
In some conditions it can happen that the client-side socket is destroyed
before the server-side socket has gracefully closed, thus causing a
'ECONNRESET' error in this socket. To solve this, wait in the client-side
socket for the 'end' event before closing it.

PR-URL: https://github.com/nodejs/node/pull/4043
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
test/parallel/test-tls-no-rsa-key.js

index 61e8a3b..ff9806c 100644 (file)
@@ -23,9 +23,16 @@ var server = tls.createServer(options, function(conn) {
   var c = tls.connect(common.PORT, {
     rejectUnauthorized: false
   }, function() {
+    c.on('end', common.mustCall(function() {
+      c.end();
+      server.close();
+    }));
+
+    c.on('data', function(data) {
+      assert.equal(data, 'ok');
+    });
+
     cert = c.getPeerCertificate();
-    c.destroy();
-    server.close();
   });
 });