|
|
|
@ -47,6 +47,27 @@ var mathService = math_proto.lookup('math.Math'); |
|
|
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This is used for testing functions with multiple asynchronous calls that |
|
|
|
|
* can happen in different orders. This should be passed the number of async |
|
|
|
|
* function invocations that can occur last, and each of those should call this |
|
|
|
|
* function's return value |
|
|
|
|
* @param {function()} done The function that should be called when a test is |
|
|
|
|
* complete. |
|
|
|
|
* @param {number} count The number of calls to the resulting function if the |
|
|
|
|
* test passes. |
|
|
|
|
* @return {function()} The function that should be called at the end of each |
|
|
|
|
* sequence of asynchronous functions. |
|
|
|
|
*/ |
|
|
|
|
function multiDone(done, count) { |
|
|
|
|
return function() { |
|
|
|
|
count -= 1; |
|
|
|
|
if (count <= 0) { |
|
|
|
|
done(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var server_insecure_creds = grpc.ServerCredentials.createInsecure(); |
|
|
|
|
|
|
|
|
|
describe('File loader', function() { |
|
|
|
@ -272,12 +293,14 @@ describe('Echo metadata', function() { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
describe('Other conditions', function() { |
|
|
|
|
var test_service; |
|
|
|
|
var Client; |
|
|
|
|
var client; |
|
|
|
|
var server; |
|
|
|
|
var port; |
|
|
|
|
before(function() { |
|
|
|
|
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto'); |
|
|
|
|
var test_service = test_proto.lookup('TestService'); |
|
|
|
|
test_service = test_proto.lookup('TestService'); |
|
|
|
|
server = new grpc.Server(); |
|
|
|
|
server.addProtoService(test_service, { |
|
|
|
|
unary: function(call, cb) { |
|
|
|
@ -339,7 +362,7 @@ describe('Other conditions', function() { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
port = server.bind('localhost:0', server_insecure_creds); |
|
|
|
|
var Client = surface_client.makeProtobufClientConstructor(test_service); |
|
|
|
|
Client = surface_client.makeProtobufClientConstructor(test_service); |
|
|
|
|
client = new Client('localhost:' + port, grpc.Credentials.createInsecure()); |
|
|
|
|
server.start(); |
|
|
|
|
}); |
|
|
|
@ -592,6 +615,162 @@ describe('Other conditions', function() { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
describe('Call propagation', function() { |
|
|
|
|
var proxy; |
|
|
|
|
var proxy_impl; |
|
|
|
|
beforeEach(function() { |
|
|
|
|
proxy = new grpc.Server(); |
|
|
|
|
proxy_impl = { |
|
|
|
|
unary: function(call) {}, |
|
|
|
|
clientStream: function(stream) {}, |
|
|
|
|
serverStream: function(stream) {}, |
|
|
|
|
bidiStream: function(stream) {} |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
afterEach(function() { |
|
|
|
|
console.log('Shutting down server'); |
|
|
|
|
proxy.shutdown(); |
|
|
|
|
}); |
|
|
|
|
describe('Cancellation', function() { |
|
|
|
|
it('With a unary call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.unary = function(parent, callback) { |
|
|
|
|
client.unary(parent.request, function(err, value) { |
|
|
|
|
try { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.CANCELLED); |
|
|
|
|
} finally { |
|
|
|
|
callback(err, value); |
|
|
|
|
done(); |
|
|
|
|
} |
|
|
|
|
}, null, {parent: parent}); |
|
|
|
|
call.cancel(); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var call = proxy_client.unary({}, function(err, value) { |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
it('With a client stream call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.clientStream = function(parent, callback) { |
|
|
|
|
client.clientStream(function(err, value) { |
|
|
|
|
try { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.CANCELLED); |
|
|
|
|
} finally { |
|
|
|
|
callback(err, value); |
|
|
|
|
done(); |
|
|
|
|
} |
|
|
|
|
}, null, {parent: parent}); |
|
|
|
|
call.cancel(); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var call = proxy_client.clientStream(function(err, value) { |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
it('With a server stream call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.serverStream = function(parent) { |
|
|
|
|
var child = client.serverStream(parent.request, null, |
|
|
|
|
{parent: parent}); |
|
|
|
|
child.on('error', function(err) { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.CANCELLED); |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
call.cancel(); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var call = proxy_client.serverStream({}); |
|
|
|
|
call.on('error', function(err) { |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
it('With a bidi stream call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.bidiStream = function(parent) { |
|
|
|
|
var child = client.bidiStream(null, {parent: parent}); |
|
|
|
|
child.on('error', function(err) { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.CANCELLED); |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
call.cancel(); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var call = proxy_client.bidiStream(); |
|
|
|
|
call.on('error', function(err) { |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
describe('Deadline', function() { |
|
|
|
|
it.skip('With a client stream call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.clientStream = function(parent, callback) { |
|
|
|
|
client.clientStream(function(err, value) { |
|
|
|
|
try { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.DEADLINE_EXCEEDED); |
|
|
|
|
} finally { |
|
|
|
|
callback(err, value); |
|
|
|
|
done(); |
|
|
|
|
} |
|
|
|
|
}, null, {parent: parent}); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var deadline = new Date(); |
|
|
|
|
deadline.setSeconds(deadline.getSeconds() + 1); |
|
|
|
|
var call = proxy_client.clientStream(function(err, value) { |
|
|
|
|
done(); |
|
|
|
|
}, null, {deadline: deadline}); |
|
|
|
|
}); |
|
|
|
|
it.skip('With a bidi stream call', function(done) { |
|
|
|
|
done = multiDone(done, 2); |
|
|
|
|
proxy_impl.bidiStream = function(parent) { |
|
|
|
|
var child = client.bidiStream(null, {parent: parent}); |
|
|
|
|
child.on('error', function(err) { |
|
|
|
|
assert(err); |
|
|
|
|
assert.strictEqual(err.code, grpc.status.DEADLINE_EXCEEDED); |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
proxy.addProtoService(test_service, proxy_impl); |
|
|
|
|
var proxy_port = proxy.bind('localhost:0', server_insecure_creds); |
|
|
|
|
proxy.start(); |
|
|
|
|
var proxy_client = new Client('localhost:' + proxy_port, |
|
|
|
|
grpc.Credentials.createInsecure()); |
|
|
|
|
var deadline = new Date(); |
|
|
|
|
deadline.setSeconds(deadline.getSeconds() + 1); |
|
|
|
|
var call = proxy_client.bidiStream(null, {deadline: deadline}); |
|
|
|
|
call.on('error', function(err) { |
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
describe('Cancelling surface client', function() { |
|
|
|
|
var client; |
|
|
|
|