Skip to content

Commit c41c3da

Browse files
committed
Test ring_hash fallback on dropped connection
1 parent 0b2281b commit c41c3da

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

packages/grpc-js-xds/test/test-ring-hash.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,59 @@ describe('Ring hash LB policy', () => {
115115
})
116116
}, reason => done(reason));
117117
});
118+
it('Should fallback to a second backend if the first one goes down', function(done) {
119+
if (!EXPERIMENTAL_RING_HASH) {
120+
this.skip();
121+
}
122+
const backends = [new Backend(), new Backend(), new Backend()];
123+
const cluster = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: backends, locality:{region: 'region1'}}], 'RING_HASH');
124+
const routeGroup = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster}]);
125+
routeGroup.startAllBackends().then(() => {
126+
xdsServer.setEdsResource(cluster.getEndpointConfig());
127+
xdsServer.setCdsResource(cluster.getClusterConfig());
128+
xdsServer.setRdsResource(routeGroup.getRouteConfiguration());
129+
xdsServer.setLdsResource(routeGroup.getListener());
130+
xdsServer.addResponseListener((typeUrl, responseState) => {
131+
if (responseState.state === 'NACKED') {
132+
client.stopCalls();
133+
assert.fail(`Client NACKED ${typeUrl} resource with message ${responseState.errorMessage}`);
134+
}
135+
})
136+
client = XdsTestClient.createFromServer('listener1', xdsServer);
137+
client.sendNCalls(100, error => {
138+
assert.ifError(error);
139+
let backendWithTraffic: number | null = null;
140+
for (let i = 0; i < backends.length; i++) {
141+
if (backendWithTraffic === null) {
142+
if (backends[i].getCallCount() > 0) {
143+
backendWithTraffic = i;
144+
}
145+
} else {
146+
assert.strictEqual(backends[i].getCallCount(), 0, `Backends ${backendWithTraffic} and ${i} both got traffic`);
147+
}
148+
}
149+
assert.notStrictEqual(backendWithTraffic, null, 'No backend got traffic');
150+
backends[backendWithTraffic!].shutdown(error => {
151+
assert.ifError(error);
152+
backends[backendWithTraffic!].resetCallCount();
153+
client.sendNCalls(100, error => {
154+
assert.ifError(error);
155+
let backendWithTraffic2: number | null = null;
156+
for (let i = 0; i < backends.length; i++) {
157+
if (backendWithTraffic2 === null) {
158+
if (backends[i].getCallCount() > 0) {
159+
backendWithTraffic2 = i;
160+
}
161+
} else {
162+
assert.strictEqual(backends[i].getCallCount(), 0, `Backends ${backendWithTraffic2} and ${i} both got traffic`);
163+
}
164+
}
165+
assert.notStrictEqual(backendWithTraffic2, null, 'No backend got traffic');
166+
assert.notStrictEqual(backendWithTraffic2, backendWithTraffic, `Traffic went to the same backend ${backendWithTraffic} after shutdown`);
167+
done();
168+
});
169+
});
170+
});
171+
}, reason => done(reason));
172+
})
118173
});

0 commit comments

Comments
 (0)