aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-10-12 13:18:06 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-10-12 13:18:06 -0700
commit6fe015e492ef41f533ac3441882c437a7560b977 (patch)
treeea5ef53711f8d1d5ebc22ef88cda50b29d2695c0 /src
parent3e1b97225d56ab08416b924d735ce8e53e70f205 (diff)
Add some tests to increase coverage, fix some failures
Diffstat (limited to 'src')
-rw-r--r--src/node/ext/call.cc6
-rw-r--r--src/node/interop/interop_client.js1
-rw-r--r--src/node/src/credentials.js3
-rw-r--r--src/node/test/call_test.js48
-rw-r--r--src/node/test/channel_test.js1
-rw-r--r--src/node/test/credentials_test.js18
-rw-r--r--src/node/test/health_test.js20
-rw-r--r--src/node/test/interop_sanity_test.js2
-rw-r--r--src/node/test/surface_test.js6
9 files changed, 96 insertions, 9 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index b63e294f9a..fcad62261f 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -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);
}
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index cb55083d1a..b5061895cf 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -35,7 +35,6 @@
var fs = require('fs');
var path = require('path');
-var _ = require('lodash');
var grpc = require('..');
var testProto = grpc.load({
root: __dirname + '/../../..',
diff --git a/src/node/src/credentials.js b/src/node/src/credentials.js
index ddc094f896..ff10a22e6a 100644
--- a/src/node/src/credentials.js
+++ b/src/node/src/credentials.js
@@ -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());
});
diff --git a/src/node/test/call_test.js b/src/node/test/call_test.js
index c316fe7f10..b7f4f56510 100644
--- a/src/node/test/call_test.js
+++ b/src/node/test/call_test.js
@@ -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));
diff --git a/src/node/test/channel_test.js b/src/node/test/channel_test.js
index 05269f7b6e..5bcf63ee50 100644
--- a/src/node/test/channel_test.js
+++ b/src/node/test/channel_test.js
@@ -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();
});
});
diff --git a/src/node/test/credentials_test.js b/src/node/test/credentials_test.js
index 7fc311a888..960405ab3b 100644
--- a/src/node/test/credentials_test.js
+++ b/src/node/test/credentials_test.js
@@ -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;
diff --git a/src/node/test/health_test.js b/src/node/test/health_test.js
index a4dc24cf46..c93b528d42 100644
--- a/src/node/test/health_test.js
+++ b/src/node/test/health_test.js
@@ -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();
+ });
+ });
+ });
});
diff --git a/src/node/test/interop_sanity_test.js b/src/node/test/interop_sanity_test.js
index f8c0b14137..f008a87585 100644
--- a/src/node/test/interop_sanity_test.js
+++ b/src/node/test/interop_sanity_test.js
@@ -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) {
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 395ea887ec..71801c38dd 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -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 {