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

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

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

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

Loading…
Cancel
Save