mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
Add some tests to increase coverage, fix some failures
This commit is contained in:
parent
c00bf4f6bc
commit
be6598082f
@ -712,7 +712,11 @@ NAN_METHOD(Call::CancelWithStatus) {
|
||||
Call *call = ObjectWrap::Unwrap<Call>(info.This());
|
||||
grpc_status_code code = static_cast<grpc_status_code>(
|
||||
Nan::To<uint32_t>(info[0]).FromJust());
|
||||
Utf8String details(info[0]);
|
||||
if (code == GRPC_STATUS_OK) {
|
||||
return Nan::ThrowRangeError(
|
||||
"cancelWithStatus cannot be called with OK status");
|
||||
}
|
||||
Utf8String details(info[1]);
|
||||
grpc_call_cancel_with_status(call->wrapped_call, code, *details, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var grpc = require('..');
|
||||
var testProto = grpc.load({
|
||||
root: __dirname + '/../../..',
|
||||
|
||||
@ -99,6 +99,9 @@ exports.createFromMetadataGenerator = function(metadata_generator) {
|
||||
if (error.hasOwnProperty('code')) {
|
||||
code = error.code;
|
||||
}
|
||||
if (!metadata) {
|
||||
metadata = new Metadata();
|
||||
}
|
||||
}
|
||||
callback(code, message, metadata._getCoreRepresentation());
|
||||
});
|
||||
|
||||
@ -108,6 +108,17 @@ describe('call', function() {
|
||||
}, TypeError);
|
||||
});
|
||||
});
|
||||
describe('deadline', function() {
|
||||
it('should time out immediately with negative deadline', function(done) {
|
||||
var call = new grpc.Call(channel, 'method', -Infinity);
|
||||
var batch = {};
|
||||
batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
|
||||
call.startBatch(batch, function(err, response) {
|
||||
assert.strictEqual(response.status.code, grpc.status.DEADLINE_EXCEEDED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('startBatch', function() {
|
||||
it('should fail without an object and a function', function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
@ -192,6 +203,43 @@ describe('call', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('cancelWithStatus', function() {
|
||||
it('should reject anything other than an integer and a string', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
call.cancelWithStatus(1, 'details');
|
||||
});
|
||||
assert.throws(function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
call.cancelWithStatus();
|
||||
});
|
||||
assert.throws(function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
call.cancelWithStatus('');
|
||||
});
|
||||
assert.throws(function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
call.cancelWithStatus(5, {});
|
||||
});
|
||||
});
|
||||
it('should reject the OK status code', function() {
|
||||
assert.throws(function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
call.cancelWithStatus(0, 'details');
|
||||
});
|
||||
});
|
||||
it('should result in the call ending with a status', function(done) {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
var batch = {};
|
||||
batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
|
||||
call.startBatch(batch, function(err, response) {
|
||||
assert.strictEqual(response.status.code, 5);
|
||||
assert.strictEqual(response.status.details, 'details');
|
||||
done();
|
||||
});
|
||||
call.cancelWithStatus(5, 'details');
|
||||
});
|
||||
});
|
||||
describe('getPeer', function() {
|
||||
it('should return a string', function() {
|
||||
var call = new grpc.Call(channel, 'method', getDeadline(1));
|
||||
|
||||
@ -155,7 +155,6 @@ describe('channel', function() {
|
||||
deadline.setSeconds(deadline.getSeconds() + 1);
|
||||
channel.watchConnectivityState(old_state, deadline, function(err, value) {
|
||||
assert(err);
|
||||
console.log('Callback from watchConnectivityState');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@ -169,6 +169,24 @@ describe('client credentials', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it.skip('should propagate errors that the updater emits', function(done) {
|
||||
var metadataUpdater = function(service_url, callback) {
|
||||
var error = new Error('Authentication error');
|
||||
error.code = grpc.status.UNAUTHENTICATED;
|
||||
callback(error);
|
||||
};
|
||||
var creds = grpc.credentials.createFromMetadataGenerator(metadataUpdater);
|
||||
var combined_creds = grpc.credentials.combineChannelCredentials(
|
||||
client_ssl_creds, creds);
|
||||
var client = new Client('localhost:' + port, combined_creds,
|
||||
client_options);
|
||||
client.unary({}, function(err, data) {
|
||||
assert(err);
|
||||
assert.strictEqual(err.message, 'Authentication error');
|
||||
assert.strictEqual(err.code, grpc.status.UNAUTHENTICATED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('Per-rpc creds', function() {
|
||||
var client;
|
||||
var updater_creds;
|
||||
|
||||
@ -45,11 +45,13 @@ describe('Health Checking', function() {
|
||||
'grpc.test.TestServiceNotServing': 'NOT_SERVING',
|
||||
'grpc.test.TestServiceServing': 'SERVING'
|
||||
};
|
||||
var healthServer = new grpc.Server();
|
||||
healthServer.addProtoService(health.service,
|
||||
new health.Implementation(statusMap));
|
||||
var healthServer;
|
||||
var healthImpl;
|
||||
var healthClient;
|
||||
before(function() {
|
||||
healthServer = new grpc.Server();
|
||||
healthImpl = new health.Implementation(statusMap);
|
||||
healthServer.addProtoService(health.service, healthImpl);
|
||||
var port_num = healthServer.bind('0.0.0.0:0',
|
||||
grpc.ServerCredentials.createInsecure());
|
||||
healthServer.start();
|
||||
@ -89,4 +91,16 @@ describe('Health Checking', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should get a different response if the status changes', function(done) {
|
||||
healthClient.check({service: 'transient'}, function(err, response) {
|
||||
assert(err);
|
||||
assert.strictEqual(err.code, grpc.status.NOT_FOUND);
|
||||
healthImpl.setStatus('transient', 'SERVING');
|
||||
healthClient.check({service: 'transient'}, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(response.status, 'SERVING');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -71,7 +71,7 @@ describe('Interop tests', function() {
|
||||
interop_client.runTest(port, name_override, 'server_streaming', true, true,
|
||||
done);
|
||||
});
|
||||
it.only('should pass ping_pong', function(done) {
|
||||
it('should pass ping_pong', function(done) {
|
||||
interop_client.runTest(port, name_override, 'ping_pong', true, true, done);
|
||||
});
|
||||
it('should pass empty_stream', function(done) {
|
||||
|
||||
@ -382,7 +382,8 @@ describe('Other conditions', function() {
|
||||
unary: function(call, cb) {
|
||||
var req = call.request;
|
||||
if (req.error) {
|
||||
cb(new Error('Requested error'), null, trailer_metadata);
|
||||
cb({code: grpc.status.UNKNOWN,
|
||||
details: 'Requested error'}, null, trailer_metadata);
|
||||
} else {
|
||||
cb(null, {count: 1}, trailer_metadata);
|
||||
}
|
||||
@ -407,7 +408,8 @@ describe('Other conditions', function() {
|
||||
serverStream: function(stream) {
|
||||
var req = stream.request;
|
||||
if (req.error) {
|
||||
var err = new Error('Requested error');
|
||||
var err = {code: grpc.status.UNKNOWN,
|
||||
details: 'Requested error'};
|
||||
err.metadata = trailer_metadata;
|
||||
stream.emit('error', err);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user