|
|
@ -35,15 +35,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
var assert = require('assert'); |
|
|
|
var assert = require('assert'); |
|
|
|
|
|
|
|
|
|
|
|
var health = require('../health_check/health.js'); |
|
|
|
var health = require('../health_check/health'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var health_messages = require('../health_check/v1/health_pb'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ServingStatus = health_messages.HealthCheckResponse.ServingStatus; |
|
|
|
|
|
|
|
|
|
|
|
var grpc = require('../'); |
|
|
|
var grpc = require('../'); |
|
|
|
|
|
|
|
|
|
|
|
describe('Health Checking', function() { |
|
|
|
describe('Health Checking', function() { |
|
|
|
var statusMap = { |
|
|
|
var statusMap = { |
|
|
|
'': 'SERVING', |
|
|
|
'': ServingStatus.SERVING, |
|
|
|
'grpc.test.TestServiceNotServing': 'NOT_SERVING', |
|
|
|
'grpc.test.TestServiceNotServing': ServingStatus.NOT_SERVING, |
|
|
|
'grpc.test.TestServiceServing': 'SERVING' |
|
|
|
'grpc.test.TestServiceServing': ServingStatus.SERVING |
|
|
|
}; |
|
|
|
}; |
|
|
|
var healthServer; |
|
|
|
var healthServer; |
|
|
|
var healthImpl; |
|
|
|
var healthImpl; |
|
|
@ -51,7 +55,7 @@ describe('Health Checking', function() { |
|
|
|
before(function() { |
|
|
|
before(function() { |
|
|
|
healthServer = new grpc.Server(); |
|
|
|
healthServer = new grpc.Server(); |
|
|
|
healthImpl = new health.Implementation(statusMap); |
|
|
|
healthImpl = new health.Implementation(statusMap); |
|
|
|
healthServer.addProtoService(health.service, healthImpl); |
|
|
|
healthServer.addService(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(); |
|
|
@ -62,43 +66,51 @@ describe('Health Checking', function() { |
|
|
|
healthServer.forceShutdown(); |
|
|
|
healthServer.forceShutdown(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should say an enabled service is SERVING', function(done) { |
|
|
|
it('should say an enabled service is SERVING', function(done) { |
|
|
|
healthClient.check({service: ''}, function(err, response) { |
|
|
|
var request = new health_messages.HealthCheckRequest(); |
|
|
|
|
|
|
|
request.setService(''); |
|
|
|
|
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert.ifError(err); |
|
|
|
assert.ifError(err); |
|
|
|
assert.strictEqual(response.status, 'SERVING'); |
|
|
|
assert.strictEqual(response.getStatus(), ServingStatus.SERVING); |
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should say that a disabled service is NOT_SERVING', function(done) { |
|
|
|
it('should say that a disabled service is NOT_SERVING', function(done) { |
|
|
|
healthClient.check({service: 'grpc.test.TestServiceNotServing'}, |
|
|
|
var request = new health_messages.HealthCheckRequest(); |
|
|
|
function(err, response) { |
|
|
|
request.setService('grpc.test.TestServiceNotServing'); |
|
|
|
|
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert.ifError(err); |
|
|
|
assert.ifError(err); |
|
|
|
assert.strictEqual(response.status, 'NOT_SERVING'); |
|
|
|
assert.strictEqual(response.getStatus(), ServingStatus.NOT_SERVING); |
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should say that an enabled service is SERVING', function(done) { |
|
|
|
it('should say that an enabled service is SERVING', function(done) { |
|
|
|
healthClient.check({service: 'grpc.test.TestServiceServing'}, |
|
|
|
var request = new health_messages.HealthCheckRequest(); |
|
|
|
function(err, response) { |
|
|
|
request.setService('grpc.test.TestServiceServing'); |
|
|
|
|
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert.ifError(err); |
|
|
|
assert.ifError(err); |
|
|
|
assert.strictEqual(response.status, 'SERVING'); |
|
|
|
assert.strictEqual(response.getStatus(), ServingStatus.SERVING); |
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should get NOT_FOUND if the service is not registered', function(done) { |
|
|
|
it('should get NOT_FOUND if the service is not registered', function(done) { |
|
|
|
healthClient.check({service: 'not_registered'}, function(err, response) { |
|
|
|
var request = new health_messages.HealthCheckRequest(); |
|
|
|
|
|
|
|
request.setService('not_registered'); |
|
|
|
|
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert(err); |
|
|
|
assert(err); |
|
|
|
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
|
|
|
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should get a different response if the status changes', function(done) { |
|
|
|
it('should get a different response if the status changes', function(done) { |
|
|
|
healthClient.check({service: 'transient'}, function(err, response) { |
|
|
|
var request = new health_messages.HealthCheckRequest(); |
|
|
|
|
|
|
|
request.setService('transient'); |
|
|
|
|
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert(err); |
|
|
|
assert(err); |
|
|
|
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
|
|
|
assert.strictEqual(err.code, grpc.status.NOT_FOUND); |
|
|
|
healthImpl.setStatus('transient', 'SERVING'); |
|
|
|
healthImpl.setStatus('transient', ServingStatus.SERVING); |
|
|
|
healthClient.check({service: 'transient'}, function(err, response) { |
|
|
|
healthClient.check(request, function(err, response) { |
|
|
|
assert.ifError(err); |
|
|
|
assert.ifError(err); |
|
|
|
assert.strictEqual(response.status, 'SERVING'); |
|
|
|
assert.strictEqual(response.getStatus(), ServingStatus.SERVING); |
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|