aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Michael Lumish <mlumish@google.com>2016-12-15 15:37:08 -0800
committerGravatar GitHub <noreply@github.com>2016-12-15 15:37:08 -0800
commit2cf4f35a3820b7d3d3c67d78cebefaadfc549a02 (patch)
treeacc8bd8d49ee3cc848faba8dd505c828c0e194ca
parenta78109500101dd4afee6183e5e1678d03d24110a (diff)
parent5eebc93b1d7bf0f1e878ce2193c6e58d9e637211 (diff)
Merge pull request #9101 from murgatroid99/node_event_changes
Make event order consistent, and make 'end' and 'error' mutually exclusive
-rw-r--r--src/node/src/client.js13
-rw-r--r--src/node/test/surface_test.js8
2 files changed, 12 insertions, 9 deletions
diff --git a/src/node/src/client.js b/src/node/src/client.js
index 9c1562e8b8..0f85f2c63a 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.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;
}
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index d8b36dc55c..2a42dd5db5 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -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();