Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Nov 7, 2024
1 parent ac9ad67 commit ec9b3cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/grpc-js-xds/test/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class FakeServerRoute {
private listener: Listener;
private routeConfiguration: RouteConfiguration;
constructor(port: number, routeName: string, baseListener?: Listener | undefined, baseRouteConfiguration?: RouteConfiguration) {
this.listener = baseListener ?? DEFAULT_BASE_SERVER_LISTENER;
this.listener = baseListener ?? {...DEFAULT_BASE_SERVER_LISTENER};
this.listener.name = `[::1]:${port}`;
this.listener.address = {
socket_address: {
Expand Down Expand Up @@ -414,7 +414,7 @@ export class FakeServerRoute {
filterChain.filters = filterList;
}

this.routeConfiguration = baseRouteConfiguration ?? DEFAULT_BASE_SERVER_ROUTE_CONFIG;
this.routeConfiguration = baseRouteConfiguration ?? {...DEFAULT_BASE_SERVER_ROUTE_CONFIG};
this.routeConfiguration.name = routeName;
}

Expand Down
31 changes: 31 additions & 0 deletions packages/grpc-js-xds/test/test-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,36 @@ describe('core xDS functionality', () => {
});
}, reason => done(reason));
}, reason => done(reason));
});
it('should handle cluster config changes', async () => {
const [backend1, backend2] = await createBackends(2);
const serverRoute1 = new FakeServerRoute(backend1.getPort(), 'serverRoute');
const serverRoute2 = new FakeServerRoute(backend2.getPort(), 'serverRoute2');
xdsServer.setRdsResource(serverRoute1.getRouteConfiguration());
xdsServer.setLdsResource(serverRoute1.getListener());
xdsServer.setRdsResource(serverRoute2.getRouteConfiguration());
xdsServer.setLdsResource(serverRoute2.getListener());
xdsServer.addResponseListener((typeUrl, responseState) => {
if (responseState.state === 'NACKED') {
client?.stopCalls();
assert.fail(`Client NACKED ${typeUrl} resource with message ${responseState.errorMessage}`);
}
});
const cluster1 = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [backend1], locality:{region: 'region1'}}]);
const routeGroup1 = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster1}]);
await routeGroup1.startAllBackends(xdsServer);
xdsServer.setEdsResource(cluster1.getEndpointConfig());
xdsServer.setCdsResource(cluster1.getClusterConfig());
xdsServer.setRdsResource(routeGroup1.getRouteConfiguration());
xdsServer.setLdsResource(routeGroup1.getListener());
client = XdsTestClient.createFromServer('listener1', xdsServer);
client.startCalls(100);
await cluster1.waitForAllBackendsToReceiveTraffic();
const cluster2 = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [backend2], locality:{region: 'region2'}}]);
await cluster2.startAllBackends(xdsServer);
xdsServer.setEdsResource(cluster2.getEndpointConfig());
await cluster2.waitForAllBackendsToReceiveTraffic();
client.stopCalls();

})
});

0 comments on commit ec9b3cf

Please sign in to comment.