Skip to content

Commit

Permalink
grpc: listen for metadata event instead of status
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Jul 21, 2016
1 parent 5689f96 commit e56bdbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {

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

this.emit('response', grcpStatus || status);
Expand Down
27 changes: 25 additions & 2 deletions test/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ describe('GrpcService', function() {
);
});

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

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

fakeStream.received_status = grpcError500;

fakeStream
.on('response', function(resp) {
assert.deepEqual(resp, GrpcService.GRPC_ERROR_CODE_TO_HTTP[2]);
done();
});

grpcService.requestStream(PROTO_OPTS, REQ_OPTS);
fakeStream.emit('status', grpcError500);
fakeStream.emit('metadata');
});

it('should default to OK status when metadata fires', function(done) {
var fakeStream = through.obj();

ProtoService.prototype.method = function() {
return fakeStream;
};

retryRequestOverride = function(reqOpts, options) {
return options.request();
};

fakeStream
.on('response', function(resp) {
assert.deepEqual(resp, GrpcService.GRPC_ERROR_CODE_TO_HTTP[0]);
done();
});

grpcService.requestStream(PROTO_OPTS, REQ_OPTS);
fakeStream.emit('metadata');
});

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

0 comments on commit e56bdbf

Please sign in to comment.