Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc: listen for metadata event instead of status #1444

Merged
merged 4 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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) {

This comment was marked as spam.

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