diff --git a/packages/grpc-js-xds/gulpfile.ts b/packages/grpc-js-xds/gulpfile.ts index 2bb43a7f..93f93d8f 100644 --- a/packages/grpc-js-xds/gulpfile.ts +++ b/packages/grpc-js-xds/gulpfile.ts @@ -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']})); diff --git a/packages/grpc-js-xds/package.json b/packages/grpc-js-xds/package.json index 9d254854..6ec4548d 100644 --- a/packages/grpc-js-xds/package.json +++ b/packages/grpc-js-xds/package.json @@ -53,7 +53,7 @@ "@grpc/grpc-js": "~1.8.0" }, "engines": { - "node": ">=16.0.0" + "node": ">=10.10.0" }, "files": [ "src/**/*.ts", diff --git a/packages/grpc-js-xds/src/resolver-xds.ts b/packages/grpc-js-xds/src/resolver-xds.ts index 3acdd232..5182e100 100644 --- a/packages/grpc-js-xds/src/resolver-xds.ts +++ b/packages/grpc-js-xds/src/resolver-xds.ts @@ -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 }; diff --git a/packages/grpc-js-xds/test/test-confg-parsing.ts b/packages/grpc-js-xds/test/test-confg-parsing.ts index f2065805..c185c852 100644 --- a/packages/grpc-js-xds/test/test-confg-parsing.ts +++ b/packages/grpc-js-xds/test/test-confg-parsing.ts @@ -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(() => { diff --git a/packages/grpc-js-xds/test/test-ring-hash.ts b/packages/grpc-js-xds/test/test-ring-hash.ts index 0a9e893e..af795bc9 100644 --- a/packages/grpc-js-xds/test/test-ring-hash.ts +++ b/packages/grpc-js-xds/test/test-ring-hash.ts @@ -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)); }); -}) +}); diff --git a/run-tests.sh b/run-tests.sh index 16dff5cb..0adcc0f1 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -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