test: make connctivity test more robust

The key change here is forcing the final unary call to
wait for the server to be ready. The native client was
making the RPC, but didn't appear to have a valid
connection at the time.
This commit is contained in:
cjihrig 2019-06-25 19:39:45 -04:00
parent 7c2bb2a237
commit e9946c3f6c
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
1 changed files with 5 additions and 1 deletions

View File

@ -76,10 +76,12 @@ describe('Reconnection', function() {
});
});
after(function() {
client.close();
server1.forceShutdown();
server2.forceShutdown();
});
it('Should end with either OK or UNAVAILABLE when querying a server that is shutting down', function(done) {
this.timeout(10000);
let pendingCalls = 0;
let testDone = false;
let callInterval;
@ -94,7 +96,8 @@ describe('Reconnection', function() {
server2.bindAsync(`localhost:${port}`, serverCreds, (err) => {
assert.ifError(err);
server2.start();
client.unary({}, (err, data) => {
const metadata = new clientGrpc.Metadata({ waitForReady: true });
client.unary({}, metadata, (err, data) => {
assert.ifError(err);
clearInterval(callInterval);
testDone = true;
@ -103,6 +106,7 @@ describe('Reconnection', function() {
});
});
callInterval = setInterval(() => {
assert.strictEqual(testDone, false);
pendingCalls += 1;
client.unary({}, (err, data) => {
pendingCalls -= 1;