diff --git a/src/index.ts b/src/index.ts index 983d7f9ab..f6eedf081 100644 --- a/src/index.ts +++ b/src/index.ts @@ -305,6 +305,9 @@ class Spanner extends GrpcService { libName: 'gccl', libVersion: require('../../package.json').version, scopes, + // Add grpc keep alive setting + 'grpc.keepalive_time_ms': 30000, + 'grpc.keepalive_timeout_ms': 10000, // Enable grpc-gcp support 'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer, 'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride, diff --git a/test/index.ts b/test/index.ts index 636bb845e..a2421bf9d 100644 --- a/test/index.ts +++ b/test/index.ts @@ -204,6 +204,8 @@ describe('Spanner', () => { libVersion: require('../../package.json').version, scopes: [], grpc, + 'grpc.keepalive_time_ms': 30000, + 'grpc.keepalive_timeout_ms': 10000, 'grpc.callInvocationTransformer': fakeGrpcGcp().gcpCallInvocationTransformer, 'grpc.channelFactoryOverride': fakeGrpcGcp().gcpChannelFactoryOverride, @@ -251,6 +253,24 @@ describe('Spanner', () => { ); }); + it('should override grpc settings', () => { + const keepaliveOptions = { + 'grpc.keepalive_time_ms': 300, + 'grpc.keepalive_timeout_ms': 100, + }; + const options = extend({}, OPTIONS, keepaliveOptions); + const spanner = new Spanner(options); + const expectedOptions = Object.assign( + {}, + EXPECTED_OPTIONS, + keepaliveOptions + ); + assert.deepStrictEqual( + getFake(spanner.auth).calledWith_[0], + expectedOptions + ); + }); + it('should inherit from GrpcService', () => { assert(spanner instanceof FakeGrpcService);