From 1a0e8073a1a5926d30427b4da13a60f91b39c0cb Mon Sep 17 00:00:00 2001
From: murgatroid99 <mlumish@google.com>
Date: Mon, 19 Jun 2017 13:19:49 -0700
Subject: [PATCH] Fix racy Node reconnect test

---
 src/node/test/surface_test.js | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 11577e797d..71782ae692 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -1413,13 +1413,25 @@ describe('Client reconnect', function() {
         });
         server.bind('localhost:' + port, server_insecure_creds);
         server.start();
-        client.echo(undefined, function(error, response) {
-          if (error) {
-            console.log(error);
-          }
+
+        /* We create a new client, that will not throw an error if the server
+         * is not immediately available. Instead, it will wait for the server
+         * to be available, then the call will complete. Once this happens, the
+         * original client should be able to make a new call and connect to the
+         * restarted server without having the call fail due to connection
+         * errors. */
+        var client2 = new Client('localhost:' + port,
+                                 grpc.credentials.createInsecure());
+        client2.echo({value: 'test', value2: 3}, function(error, response) {
           assert.ifError(error);
-          assert.deepEqual(response, {value: '', value2: 0});
-          done();
+          client.echo(undefined, function(error, response) {
+            if (error) {
+              console.log(error);
+            }
+            assert.ifError(error);
+            assert.deepEqual(response, {value: '', value2: 0});
+            done();
+          });
         });
       });
     });
-- 
GitLab