2015-04-27 23:54:07 +08:00
|
|
|
require(__dirname + '/../support/test_helper');
|
2014-11-05 22:42:28 +08:00
|
|
|
|
|
|
|
var assert = require('../support/assert');
|
2015-07-05 02:41:22 +08:00
|
|
|
var CartodbWindshaft = require('../../lib/cartodb/server');
|
|
|
|
var serverOptions = require('../../lib/cartodb/server_options');
|
2014-11-05 22:42:28 +08:00
|
|
|
var server = new CartodbWindshaft(serverOptions);
|
|
|
|
|
2015-03-26 01:19:40 +08:00
|
|
|
var metadataBackend = {};
|
|
|
|
var tilelive = {};
|
|
|
|
var HealthCheck = require('../../lib/cartodb/monitoring/health_check');
|
|
|
|
var healthCheck = new HealthCheck(metadataBackend, tilelive);
|
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
describe('health checks', function () {
|
2015-01-13 19:09:02 +08:00
|
|
|
|
2015-01-30 23:50:06 +08:00
|
|
|
function resetHealthConfig() {
|
2015-01-13 19:09:02 +08:00
|
|
|
global.environment.health = {
|
|
|
|
enabled: true,
|
|
|
|
username: 'localhost',
|
|
|
|
z: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
2014-11-05 22:42:28 +08:00
|
|
|
};
|
2015-01-30 23:50:06 +08:00
|
|
|
}
|
2015-01-13 19:09:02 +08:00
|
|
|
|
|
|
|
var healthCheckRequest = {
|
|
|
|
url: '/health',
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
it('returns 200 and ok=true with enabled configuration', function (done) {
|
2015-01-30 23:50:06 +08:00
|
|
|
resetHealthConfig();
|
|
|
|
|
2015-01-13 19:09:02 +08:00
|
|
|
assert.response(server,
|
|
|
|
healthCheckRequest,
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function (res, err) {
|
|
|
|
assert.ok(!err);
|
|
|
|
|
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
|
|
|
|
assert.ok(parsed.enabled);
|
|
|
|
assert.ok(parsed.ok);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-11-05 22:42:28 +08:00
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
it('error if disabled file exists', function(done) {
|
2015-03-26 01:19:40 +08:00
|
|
|
var fs = require('fs');
|
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
var readFileFn = fs.readFile;
|
2015-03-26 01:19:40 +08:00
|
|
|
fs.readFile = function(filename, callback) {
|
|
|
|
callback(null, "Maintenance");
|
2015-04-27 23:54:07 +08:00
|
|
|
};
|
2015-03-26 01:19:40 +08:00
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
healthCheck.check(null, function(err/*, result*/) {
|
2015-03-26 01:19:40 +08:00
|
|
|
assert.equal(err.message, "Maintenance");
|
|
|
|
assert.equal(err.http_status, 503);
|
|
|
|
done();
|
2015-03-26 01:41:27 +08:00
|
|
|
fs.readFile = readFileFn;
|
2015-03-26 01:19:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:54:07 +08:00
|
|
|
it('not err if disabled file does not exists', function(done) {
|
2015-03-26 01:19:40 +08:00
|
|
|
resetHealthConfig();
|
|
|
|
|
|
|
|
global.environment.disabled_file = '/tmp/ftreftrgtrccre';
|
|
|
|
|
|
|
|
assert.response(server,
|
|
|
|
healthCheckRequest,
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function (res, err) {
|
|
|
|
assert.ok(!err);
|
|
|
|
|
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
|
|
|
|
assert.equal(parsed.enabled, true);
|
|
|
|
assert.equal(parsed.ok, true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-01-13 18:29:19 +08:00
|
|
|
});
|