Merge pull request #9101 from murgatroid99/node_event_changes

Make event order consistent, and make 'end' and 'error' mutually exclusive
pull/9136/head
Michael Lumish 8 years ago committed by GitHub
commit 2cf4f35a38
  1. 13
      src/node/src/client.js
  2. 8
      src/node/test/surface_test.js

@ -184,14 +184,15 @@ function _emitStatusIfDone() {
} else {
status = this.received_status;
}
this.emit('status', status);
if (status.code !== grpc.status.OK) {
if (status.code === grpc.status.OK) {
this.push(null);
} else {
var error = new Error(status.details);
error.code = status.code;
error.metadata = status.metadata;
this.emit('error', error);
return;
}
this.emit('status', status);
}
}
@ -224,9 +225,11 @@ function _read(size) {
} catch (e) {
self._readsDone({code: grpc.status.INTERNAL,
details: 'Failed to parse server response'});
return;
}
if (data === null) {
self._readsDone();
return;
}
if (self.push(deserialized) && data !== null) {
var read_batch = {};
@ -396,6 +399,8 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
var status = response.status;
var error;
var deserialized;
emitter.emit('metadata', Metadata._fromCoreRepresentation(
response.metadata));
if (status.code === grpc.status.OK) {
if (err) {
// Got a batch error, but OK status. Something went wrong
@ -423,8 +428,6 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
args.callback(null, deserialized);
}
emitter.emit('status', status);
emitter.emit('metadata', Metadata._fromCoreRepresentation(
response.metadata));
});
return emitter;
}

@ -179,8 +179,8 @@ describe('Server.prototype.addProtoService', function() {
call.on('data', function(value) {
assert.fail('No messages expected');
});
call.on('status', function(status) {
assert.strictEqual(status.code, grpc.status.UNIMPLEMENTED);
call.on('error', function(err) {
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
done();
});
});
@ -189,8 +189,8 @@ describe('Server.prototype.addProtoService', function() {
call.on('data', function(value) {
assert.fail('No messages expected');
});
call.on('status', function(status) {
assert.strictEqual(status.code, grpc.status.UNIMPLEMENTED);
call.on('error', function(err) {
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
done();
});
call.end();

Loading…
Cancel
Save