Fixed test and lint errors

pull/3012/head
murgatroid99 9 years ago
parent 5bb9fc1789
commit f441b3fdf2
  1. 20
      src/node/src/client.js
  2. 6
      src/node/src/metadata.js
  3. 7
      src/node/src/server.js
  4. 1
      src/node/test/surface_test.js

@ -294,12 +294,13 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
client_batch[grpc.opType.RECV_MESSAGE] = true;
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
call.startBatch(client_batch, function(err, response) {
response.status.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
emitter.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
error.metadata = response.status.metadata;
callback(error);
return;
} else {
@ -371,12 +372,13 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
client_batch[grpc.opType.RECV_MESSAGE] = true;
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
call.startBatch(client_batch, function(err, response) {
response.status.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
stream.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
error.metadata = response.status.metadata;
callback(error);
return;
} else {
@ -451,12 +453,13 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
var status_batch = {};
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
call.startBatch(status_batch, function(err, response) {
response.status.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
stream.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
error.metadata = response.status.metadata;
stream.emit('error', error);
return;
} else {
@ -522,12 +525,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
var status_batch = {};
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
call.startBatch(status_batch, function(err, response) {
response.status.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
stream.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = Metadata._fromCoreRepresentation(
response.status.metadata);
error.metadata = response.status.metadata;
stream.emit('error', error);
return;
} else {

@ -139,7 +139,7 @@ Metadata.prototype.clone = function() {
var copy = new Metadata();
copy._internal_repr = _.cloneDeep(this._internal_repr);
return copy;
}
};
/**
* Gets the metadata in the format used by interal code. Intended for internal
@ -160,7 +160,9 @@ Metadata.prototype._getCoreRepresentation = function() {
*/
Metadata._fromCoreRepresentation = function(metadata) {
var newMetadata = new Metadata();
newMetadata._internal_repr = _.cloneDeep(metadata);
if (metadata) {
newMetadata._internal_repr = _.cloneDeep(metadata);
}
return newMetadata;
};

@ -167,7 +167,10 @@ function setUpWritable(stream, serialize) {
batch[grpc.opType.SEND_INITIAL_METADATA] =
(new Metadata())._getCoreRepresentation();
}
stream.status.metadata = stream.status.metadata._getCoreRepresentation();
if (stream.status.metadata) {
stream.status.metadata = stream.status.metadata._getCoreRepresentation();
}
batch[grpc.opType.SEND_STATUS_FROM_SERVER] = stream.status;
stream.call.startBatch(batch, function(){});
}
@ -181,7 +184,7 @@ function setUpWritable(stream, serialize) {
function setStatus(err) {
var code = grpc.status.UNKNOWN;
var details = 'Unknown Error';
var metadata = {};
var metadata = new Metadata();
if (err.hasOwnProperty('message')) {
details = err.message;
}

@ -359,6 +359,7 @@ describe('Other conditions', function() {
test_service = test_proto.lookup('TestService');
server = new grpc.Server();
var trailer_metadata = new grpc.Metadata();
trailer_metadata.add('trailer_present', 'yes');
server.addProtoService(test_service, {
unary: function(call, cb) {
var req = call.request;

Loading…
Cancel
Save