Revert version support change, run ring_hash tests conditionallly

This commit is contained in:
Michael Lumish 2023-09-08 10:12:14 -07:00
parent 9e487e44ab
commit 0b2281b028
6 changed files with 40 additions and 14 deletions

View File

@ -63,7 +63,9 @@ const compile = checkTask(() => execNpmCommand('compile'));
const runTests = checkTask(() => {
process.env.GRPC_EXPERIMENTAL_XDS_FEDERATION = 'true';
process.env.GRPC_EXPERIMENTAL_XDS_CUSTOM_LB_CONFIG = 'true';
process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH = 'true';
if (Number(process.versions.node.split('.')[0]) > 14) {
process.env.GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH = 'true';
}
return gulp.src(`${outDir}/test/**/*.js`)
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
require: ['ts-node/register']}));

View File

@ -53,7 +53,7 @@
"@grpc/grpc-js": "~1.8.0"
},
"engines": {
"node": ">=16.0.0"
"node": ">=10.10.0"
},
"files": [
"src/**/*.ts",

View File

@ -587,11 +587,16 @@ class XdsResolver implements Resolver {
const onCommitted = () => {
this.unrefCluster(clusterResult.name);
}
const hash = action.getHash(metadata, channelId);
let hash: string;
if (EXPERIMENTAL_RING_HASH) {
hash = `${action.getHash(metadata, channelId)}`;
} else {
hash = '';
}
return {
methodConfig: clusterResult.methodConfig,
onCommitted: onCommitted,
pickInformation: {cluster: clusterResult.name, hash: `${hash}`},
pickInformation: {cluster: clusterResult.name, hash: hash},
status: status.OK,
dynamicFilterFactories: clusterResult.dynamicFilterFactories
};

View File

@ -19,6 +19,7 @@ import { experimental, LoadBalancingConfig } from "@grpc/grpc-js";
import { register } from "../src";
import assert = require("assert");
import parseLoadbalancingConfig = experimental.parseLoadBalancingConfig;
import { EXPERIMENTAL_RING_HASH } from "../src/environment";
register();
@ -34,6 +35,7 @@ interface TestCase {
input: object,
output?: object;
error?: RegExp;
skipIf?: boolean;
}
/* The main purpose of these tests is to verify that configs that are expected
@ -319,28 +321,32 @@ const allTestCases: {[lbPolicyName: string]: TestCase[]} = {
output: {
min_ring_size: 1024,
max_ring_size: 4096
}
},
skipIf: !EXPERIMENTAL_RING_HASH
},
{
name: 'populated config',
input: {
min_ring_size: 2048,
max_ring_size: 8192
}
},
skipIf: !EXPERIMENTAL_RING_HASH
},
{
name: 'min_ring_size too large',
input: {
min_ring_size: 8_388_609
},
error: /min_ring_size/
error: /min_ring_size/,
skipIf: !EXPERIMENTAL_RING_HASH
},
{
name: 'max_ring_size too large',
input: {
max_ring_size: 8_388_609
},
error: /max_ring_size/
error: /max_ring_size/,
skipIf: !EXPERIMENTAL_RING_HASH
}
]
}
@ -349,7 +355,10 @@ describe('Load balancing policy config parsing', () => {
for (const [lbPolicyName, testCases] of Object.entries(allTestCases)) {
describe(lbPolicyName, () => {
for (const testCase of testCases) {
it(testCase.name, () => {
it(testCase.name, function() {
if (testCase.skipIf) {
this.skip();
}
const lbConfigInput = {[lbPolicyName]: testCase.input};
if (testCase.error) {
assert.throws(() => {

View File

@ -25,6 +25,7 @@ import assert = require("assert");
import { Any } from "../src/generated/google/protobuf/Any";
import { AnyExtension } from "@grpc/proto-loader";
import { RingHash } from "../src/generated/envoy/extensions/load_balancing_policies/ring_hash/v3/RingHash";
import { EXPERIMENTAL_RING_HASH } from "../src/environment";
register();
@ -41,7 +42,10 @@ describe('Ring hash LB policy', () => {
client?.close();
xdsServer?.shutdownServer();
});
it('Should route requests to the single backend with the old lbPolicy field', done => {
it('Should route requests to the single backend with the old lbPolicy field', function(done) {
if (!EXPERIMENTAL_RING_HASH) {
this.skip();
}
const cluster = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [new Backend()], locality:{region: 'region1'}}], 'RING_HASH');
const routeGroup = new FakeRouteGroup('listener1', 'route1', [{cluster: cluster}]);
routeGroup.startAllBackends().then(() => {
@ -59,7 +63,10 @@ describe('Ring hash LB policy', () => {
client.sendOneCall(done);
}, reason => done(reason));
});
it('Should route requests to the single backend with the new load_balancing_policy field', done => {
it('Should route requests to the single backend with the new load_balancing_policy field', function(done) {
if (!EXPERIMENTAL_RING_HASH) {
this.skip();
}
const lbPolicy: AnyExtension & RingHash = {
'@type': 'type.googleapis.com/envoy.extensions.load_balancing_policies.ring_hash.v3.RingHash',
hash_function: 'XX_HASH'
@ -81,7 +88,10 @@ describe('Ring hash LB policy', () => {
client.sendOneCall(done);
}, reason => done(reason));
});
it('Should route all identical requests to the same backend', done => {
it('Should route all identical requests to the same backend', function(done) {
if (!EXPERIMENTAL_RING_HASH) {
this.skip();
}
const backend1 = new Backend();
const backend2 = new Backend()
const cluster = new FakeEdsCluster('cluster1', 'endpoint1', [{backends: [backend1, backend2], locality:{region: 'region1'}}], 'RING_HASH');
@ -105,4 +115,4 @@ describe('Ring hash LB policy', () => {
})
}, reason => done(reason));
});
})
});

View File

@ -28,7 +28,7 @@ cd $ROOT
git submodule update --init --recursive
if [ ! -n "$node_versions" ] ; then
node_versions="16"
node_versions="14 16"
fi
set +ex