Skip to content
Snippets Groups Projects
Commit 6fe015e4 authored by murgatroid99's avatar murgatroid99
Browse files

Add some tests to increase coverage, fix some failures

parent 3e1b9722
No related branches found
No related tags found
No related merge requests found
...@@ -712,7 +712,11 @@ NAN_METHOD(Call::CancelWithStatus) { ...@@ -712,7 +712,11 @@ NAN_METHOD(Call::CancelWithStatus) {
Call *call = ObjectWrap::Unwrap<Call>(info.This()); Call *call = ObjectWrap::Unwrap<Call>(info.This());
grpc_status_code code = static_cast<grpc_status_code>( grpc_status_code code = static_cast<grpc_status_code>(
Nan::To<uint32_t>(info[0]).FromJust()); 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); grpc_call_cancel_with_status(call->wrapped_call, code, *details, NULL);
} }
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var _ = require('lodash');
var grpc = require('..'); var grpc = require('..');
var testProto = grpc.load({ var testProto = grpc.load({
root: __dirname + '/../../..', root: __dirname + '/../../..',
......
...@@ -99,6 +99,9 @@ exports.createFromMetadataGenerator = function(metadata_generator) { ...@@ -99,6 +99,9 @@ exports.createFromMetadataGenerator = function(metadata_generator) {
if (error.hasOwnProperty('code')) { if (error.hasOwnProperty('code')) {
code = error.code; code = error.code;
} }
if (!metadata) {
metadata = new Metadata();
}
} }
callback(code, message, metadata._getCoreRepresentation()); callback(code, message, metadata._getCoreRepresentation());
}); });
......
...@@ -108,6 +108,17 @@ describe('call', function() { ...@@ -108,6 +108,17 @@ describe('call', function() {
}, TypeError); }, 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() { describe('startBatch', function() {
it('should fail without an object and a function', function() { it('should fail without an object and a function', function() {
var call = new grpc.Call(channel, 'method', getDeadline(1)); var call = new grpc.Call(channel, 'method', getDeadline(1));
...@@ -192,6 +203,43 @@ describe('call', function() { ...@@ -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() { describe('getPeer', function() {
it('should return a string', function() { it('should return a string', function() {
var call = new grpc.Call(channel, 'method', getDeadline(1)); var call = new grpc.Call(channel, 'method', getDeadline(1));
......
...@@ -155,7 +155,6 @@ describe('channel', function() { ...@@ -155,7 +155,6 @@ describe('channel', function() {
deadline.setSeconds(deadline.getSeconds() + 1); deadline.setSeconds(deadline.getSeconds() + 1);
channel.watchConnectivityState(old_state, deadline, function(err, value) { channel.watchConnectivityState(old_state, deadline, function(err, value) {
assert(err); assert(err);
console.log('Callback from watchConnectivityState');
done(); done();
}); });
}); });
......
...@@ -169,6 +169,24 @@ describe('client credentials', function() { ...@@ -169,6 +169,24 @@ describe('client credentials', function() {
done(); 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() { describe('Per-rpc creds', function() {
var client; var client;
var updater_creds; var updater_creds;
......
...@@ -45,11 +45,13 @@ describe('Health Checking', function() { ...@@ -45,11 +45,13 @@ describe('Health Checking', function() {
'grpc.test.TestServiceNotServing': 'NOT_SERVING', 'grpc.test.TestServiceNotServing': 'NOT_SERVING',
'grpc.test.TestServiceServing': 'SERVING' 'grpc.test.TestServiceServing': 'SERVING'
}; };
var healthServer = new grpc.Server(); var healthServer;
healthServer.addProtoService(health.service, var healthImpl;
new health.Implementation(statusMap));
var healthClient; var healthClient;
before(function() { 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', var port_num = healthServer.bind('0.0.0.0:0',
grpc.ServerCredentials.createInsecure()); grpc.ServerCredentials.createInsecure());
healthServer.start(); healthServer.start();
...@@ -89,4 +91,16 @@ describe('Health Checking', function() { ...@@ -89,4 +91,16 @@ describe('Health Checking', function() {
done(); 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() { ...@@ -71,7 +71,7 @@ describe('Interop tests', function() {
interop_client.runTest(port, name_override, 'server_streaming', true, true, interop_client.runTest(port, name_override, 'server_streaming', true, true,
done); 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); interop_client.runTest(port, name_override, 'ping_pong', true, true, done);
}); });
it('should pass empty_stream', function(done) { it('should pass empty_stream', function(done) {
......
...@@ -382,7 +382,8 @@ describe('Other conditions', function() { ...@@ -382,7 +382,8 @@ describe('Other conditions', function() {
unary: function(call, cb) { unary: function(call, cb) {
var req = call.request; var req = call.request;
if (req.error) { if (req.error) {
cb(new Error('Requested error'), null, trailer_metadata); cb({code: grpc.status.UNKNOWN,
details: 'Requested error'}, null, trailer_metadata);
} else { } else {
cb(null, {count: 1}, trailer_metadata); cb(null, {count: 1}, trailer_metadata);
} }
...@@ -407,7 +408,8 @@ describe('Other conditions', function() { ...@@ -407,7 +408,8 @@ describe('Other conditions', function() {
serverStream: function(stream) { serverStream: function(stream) {
var req = stream.request; var req = stream.request;
if (req.error) { if (req.error) {
var err = new Error('Requested error'); var err = {code: grpc.status.UNKNOWN,
details: 'Requested error'};
err.metadata = trailer_metadata; err.metadata = trailer_metadata;
stream.emit('error', err); stream.emit('error', err);
} else { } else {
......
...@@ -45,7 +45,8 @@ then ...@@ -45,7 +45,8 @@ then
gcov Release/obj.target/grpc/ext/*.o gcov Release/obj.target/grpc/ext/*.o
lcov --base-directory . --directory . -c -o coverage.info lcov --base-directory . --directory . -c -o coverage.info
genhtml -o ../reports/node_ext_coverage --num-spaces 2 \ genhtml -o ../reports/node_ext_coverage --num-spaces 2 \
-t 'Node gRPC test coverage' coverage.info -t 'Node gRPC test coverage' coverage.info --rc genhtml_hi_limit=95 \
--rc genhtml_med_limit=80
echo '<html><head><meta http-equiv="refresh" content="0;URL=lcov-report/index.html"></head></html>' > \ echo '<html><head><meta http-equiv="refresh" content="0;URL=lcov-report/index.html"></head></html>' > \
../reports/node_coverage/index.html ../reports/node_coverage/index.html
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment