From eb3c479e367d3de5eef5b0b0af749feb4d663654 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 24 Jun 2019 12:56:27 -0700 Subject: [PATCH] Connectivity test: ensure all calls end before ending the test --- test/api/connectivity_test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/api/connectivity_test.js b/test/api/connectivity_test.js index eb94e412..2d5280a3 100644 --- a/test/api/connectivity_test.js +++ b/test/api/connectivity_test.js @@ -76,6 +76,13 @@ describe('Reconnection', function() { server2.forceShutdown(); }); it('Should end with either OK or UNAVAILABLE when querying a server that is shutting down', function(done) { + let pendingCalls = 0; + let testDone = false; + function maybeDone() { + if (testDone && pendingCalls == 0) { + done(); + } + }; client.unary({}, (err, data) => { assert.ifError(err); server1.tryShutdown(() => { @@ -84,14 +91,18 @@ describe('Reconnection', function() { client.unary({}, (err, data) => { assert.ifError(err); clearInterval(callInterval); - done(); + testDone = true; + maybeDone(); }); }); let callInterval = setInterval(() => { + pendingCalls += 1; client.unary({}, (err, data) => { + pendingCalls -= 1; if (err) { assert.strictEqual(err.code, clientGrpc.status.UNAVAILABLE); } + maybeDone(); }); }, 0); });