Skip to content

Commit bf4c6b9

Browse files
authored
Merge pull request #925 from murgatroid99/connectivity_test_consistency
Connectivity test: ensure all calls end before ending the test
2 parents 2e13f46 + fbdeae2 commit bf4c6b9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/api/connectivity_test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ describe('Reconnection', function() {
7676
server2.forceShutdown();
7777
});
7878
it('Should end with either OK or UNAVAILABLE when querying a server that is shutting down', function(done) {
79+
let pendingCalls = 0;
80+
let testDone = false;
81+
function maybeDone() {
82+
if (testDone && pendingCalls === 0) {
83+
done();
84+
}
85+
};
7986
client.unary({}, (err, data) => {
8087
assert.ifError(err);
8188
server1.tryShutdown(() => {
@@ -84,14 +91,18 @@ describe('Reconnection', function() {
8491
client.unary({}, (err, data) => {
8592
assert.ifError(err);
8693
clearInterval(callInterval);
87-
done();
94+
testDone = true;
95+
maybeDone();
8896
});
8997
});
9098
let callInterval = setInterval(() => {
99+
pendingCalls += 1;
91100
client.unary({}, (err, data) => {
101+
pendingCalls -= 1;
92102
if (err) {
93103
assert.strictEqual(err.code, clientGrpc.status.UNAVAILABLE);
94104
}
105+
maybeDone();
95106
});
96107
}, 0);
97108
});

0 commit comments

Comments
 (0)