From cc1a135855e6640010ed2cbfb9b8196eb5f9552b Mon Sep 17 00:00:00 2001 From: Eryu Xia Date: Fri, 19 Nov 2021 01:01:18 -0800 Subject: [PATCH] Fix issue where no RPC is issued when `deadline` is specified. (#1172) --- packages/grpc-web/exports.js | 6 ++++++ test/interop/interop_client.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/grpc-web/exports.js b/packages/grpc-web/exports.js index 2f30049..3b875ea 100644 --- a/packages/grpc-web/exports.js +++ b/packages/grpc-web/exports.js @@ -19,3 +19,9 @@ module['exports']['GrpcWebClientBase'] = GrpcWebClientBase; module['exports']['RpcError'] = RpcError; module['exports']['StatusCode'] = StatusCode; module['exports']['MethodType'] = MethodType; + +// Temporary hack to fix https://github.com/grpc/grpc-web/issues/1153, which is +// caused by `goog.global` not pointing to the global scope when grpc-web is +// being imported as a CommonJS module. +// TODO: Remove this hack after `goog.global` is fixed. +goog.Timer.defaultTimerObject = (typeof globalThis !== "undefined" && globalThis) || self; diff --git a/test/interop/interop_client.js b/test/interop/interop_client.js index d1b28f5..dd86b5f 100644 --- a/test/interop/interop_client.js +++ b/test/interop/interop_client.js @@ -50,6 +50,17 @@ function doEmptyUnary(done) { }); } +function doEmptyUnaryWithDeadline(done) { + var testService = new TestServiceClient(SERVER_HOST, null, null); + const deadlineMs = 1000; // 1 second + testService.emptyCall(new Empty(), {deadline: Date.now() + deadlineMs}, + (err, response) => { + assert.ifError(err); + assert(response instanceof Empty); + done(); + }); +} + function doLargeUnary(done) { var testService = new TestServiceClient(SERVER_HOST, null, null); var req = new SimpleRequest(); @@ -167,6 +178,7 @@ function doUnimplementedMethod(done) { var testCases = { 'empty_unary': {testFunc: doEmptyUnary}, + 'empty_unary_with_deadline': {testFunc: doEmptyUnaryWithDeadline}, 'large_unary': {testFunc: doLargeUnary}, 'server_streaming': {testFunc: doServerStreaming, skipBinaryMode: true},