Merge branch 'master' into cq_create_api_changes

This commit is contained in:
Sree Kuchibhotla 2017-03-24 10:55:39 -07:00
commit ee092d9307
4 changed files with 38 additions and 4 deletions

View File

@ -47,12 +47,12 @@ namespace grpc {
namespace node {
using Nan::Callback;
using Nan::MaybeLocal;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::Value;

View File

@ -149,6 +149,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
return _.camelCase(method.name);
}), _.map(service.children, function(method) {
return {
originalName: method.name,
path: prefix + method.name,
requestStream: method.requestStream,
responseStream: method.responseStream,

View File

@ -755,9 +755,16 @@ Server.prototype.addService = function(service, implementation) {
}
var impl;
if (implementation[name] === undefined) {
common.log(grpc.logVerbosity.ERROR, 'Method handler for ' +
/* Handle the case where the method is passed with the name exactly as
written in the proto file, instead of using JavaScript function
naming style */
if (implementation[attrs.originalName] === undefined) {
common.log(grpc.logVerbosity.ERROR, 'Method handler ' + name + ' for ' +
attrs.path + ' expected but not provided');
impl = defaultHandler[method_type];
} else {
impl = _.bind(implementation[attrs.originalName], implementation);
}
} else {
impl = _.bind(implementation[name], implementation);
}

View File

@ -143,6 +143,32 @@ describe('Server.prototype.addProtoService', function() {
server.addProtoService(mathService, dummyImpls);
});
});
it('Should allow method names as originally written', function() {
var altDummyImpls = {
'Div': function() {},
'DivMany': function() {},
'Fib': function() {},
'Sum': function() {}
};
assert.doesNotThrow(function() {
server.addProtoService(mathService, altDummyImpls);
});
});
it('Should have a conflict between name variations', function() {
/* This is really testing that both name variations are actually used,
by checking that the method actually gets registered, for the
corresponding function, in both cases */
var altDummyImpls = {
'Div': function() {},
'DivMany': function() {},
'Fib': function() {},
'Sum': function() {}
};
server.addProtoService(mathService, altDummyImpls);
assert.throws(function() {
server.addProtoService(mathService, dummyImpls);
});
});
it('Should fail if the server has been started', function() {
server.start();
assert.throws(function() {