Connectivity test: ensure all calls end before ending the test

This commit is contained in:
murgatroid99 2019-06-24 12:56:27 -07:00
parent 2e13f46141
commit eb3c479e36
1 changed files with 12 additions and 1 deletions

View File

@ -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);
});