Skip to content

Commit

Permalink
Test ring_hash fallback on dropped connection
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Sep 8, 2023
1 parent 0b2281b commit c41c3da
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/grpc-js-xds/test/test-ring-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,59 @@ describe('Ring hash LB policy', () => {
})
}, reason => done(reason));
});
it('Should fallback to a second backend if the first one goes down', function(done) {
if (!EXPERIMENTAL_RING_HASH) {
this.skip();
}
const backends = [new Backend(), new Backend(), new Backend()];
const cluster = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: backends, locality:{region: 'region1'}}], 'RING_HASH');
const routeGroup = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster}]);
routeGroup.startAllBackends().then(() => {
xdsServer.setEdsResource(cluster.getEndpointConfig());
xdsServer.setCdsResource(cluster.getClusterConfig());
xdsServer.setRdsResource(routeGroup.getRouteConfiguration());
xdsServer.setLdsResource(routeGroup.getListener());
xdsServer.addResponseListener((typeUrl, responseState) => {
if (responseState.state === 'NACKED') {
client.stopCalls();
assert.fail(`Client NACKED ${typeUrl} resource with message ${responseState.errorMessage}`);
}
})
client = XdsTestClient.createFromServer('listener1', xdsServer);
client.sendNCalls(100, error => {
assert.ifError(error);
let backendWithTraffic: number | null = null;
for (let i = 0; i < backends.length; i++) {
if (backendWithTraffic === null) {
if (backends[i].getCallCount() > 0) {
backendWithTraffic = i;
}
} else {
assert.strictEqual(backends[i].getCallCount(), 0, `Backends ${backendWithTraffic} and ${i} both got traffic`);
}
}
assert.notStrictEqual(backendWithTraffic, null, 'No backend got traffic');
backends[backendWithTraffic!].shutdown(error => {
assert.ifError(error);
backends[backendWithTraffic!].resetCallCount();
client.sendNCalls(100, error => {
assert.ifError(error);
let backendWithTraffic2: number | null = null;
for (let i = 0; i < backends.length; i++) {
if (backendWithTraffic2 === null) {
if (backends[i].getCallCount() > 0) {
backendWithTraffic2 = i;
}
} else {
assert.strictEqual(backends[i].getCallCount(), 0, `Backends ${backendWithTraffic2} and ${i} both got traffic`);
}
}
assert.notStrictEqual(backendWithTraffic2, null, 'No backend got traffic');
assert.notStrictEqual(backendWithTraffic2, backendWithTraffic, `Traffic went to the same backend ${backendWithTraffic} after shutdown`);
done();
});
});
});
}, reason => done(reason));
})
});

0 comments on commit c41c3da

Please sign in to comment.