Skip to content

Commit e56bdbf

Browse files
committed
grpc: listen for metadata event instead of status
1 parent 5689f96 commit e56bdbf

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

lib/common/grpc-service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {
325325

326326
request: function() {
327327
return service[protoOpts.method](reqOpts, grpcOpts)
328-
.on('status', function(status) {
328+
.on('metadata', function() {
329+
var status = this.received_status || { code: 0 };
329330
var grcpStatus = GrpcService.decorateStatus_(status);
330331

331332
this.emit('response', grcpStatus || status);

test/common/grpc-service.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ describe('GrpcService', function() {
10621062
);
10631063
});
10641064

1065-
it('should emit the status as a response event', function(done) {
1065+
it('should emit the metadata event as a response event', function(done) {
10661066
var grpcError500 = { code: 2 };
10671067
var fakeStream = through.obj();
10681068

@@ -1074,14 +1074,37 @@ describe('GrpcService', function() {
10741074
return options.request();
10751075
};
10761076

1077+
fakeStream.received_status = grpcError500;
1078+
10771079
fakeStream
10781080
.on('response', function(resp) {
10791081
assert.deepEqual(resp, GrpcService.GRPC_ERROR_CODE_TO_HTTP[2]);
10801082
done();
10811083
});
10821084

10831085
grpcService.requestStream(PROTO_OPTS, REQ_OPTS);
1084-
fakeStream.emit('status', grpcError500);
1086+
fakeStream.emit('metadata');
1087+
});
1088+
1089+
it('should default to OK status when metadata fires', function(done) {
1090+
var fakeStream = through.obj();
1091+
1092+
ProtoService.prototype.method = function() {
1093+
return fakeStream;
1094+
};
1095+
1096+
retryRequestOverride = function(reqOpts, options) {
1097+
return options.request();
1098+
};
1099+
1100+
fakeStream
1101+
.on('response', function(resp) {
1102+
assert.deepEqual(resp, GrpcService.GRPC_ERROR_CODE_TO_HTTP[0]);
1103+
done();
1104+
});
1105+
1106+
grpcService.requestStream(PROTO_OPTS, REQ_OPTS);
1107+
fakeStream.emit('metadata');
10851108
});
10861109

10871110
it('should emit the response error', function(done) {

0 commit comments

Comments
 (0)