2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
var testHelper = require('../support/test-helper');
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var redis = require('redis');
|
|
|
|
|
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
var cartodbRedis = require('cartodb-redis');
|
|
|
|
|
2019-10-07 15:40:50 +08:00
|
|
|
var AnalysisBackend = require('../../lib/backends/analysis');
|
2016-10-20 20:02:13 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('analysis-backend limits', function () {
|
2016-10-20 20:02:13 +08:00
|
|
|
var redisClient;
|
|
|
|
var keysToDelete;
|
|
|
|
var user = 'localhost';
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
beforeEach(function () {
|
2016-10-20 20:02:13 +08:00
|
|
|
redisClient = redis.createClient(global.environment.redis.port);
|
|
|
|
keysToDelete = {};
|
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.metadataBackend = cartodbRedis({ pool: redisPool });
|
2016-10-20 20:02:13 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
|
|
|
redisClient.quit(function () {
|
2016-10-20 20:02:13 +08:00
|
|
|
testHelper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function withAnalysesLimits (limits, callback) {
|
|
|
|
redisClient.SELECT(5, function (err) {
|
2016-10-20 20:02:13 +08:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
var analysesLimitsKey = 'limits:analyses:' + user;
|
2019-10-22 01:07:24 +08:00
|
|
|
redisClient.HMSET([analysesLimitsKey].concat(limits), function (err) {
|
2016-10-20 20:02:13 +08:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
keysToDelete[analysesLimitsKey] = 5;
|
|
|
|
return callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should use limits from configuration', function (done) {
|
2016-11-11 01:41:59 +08:00
|
|
|
var analysisBackend = new AnalysisBackend(this.metadataBackend, {
|
|
|
|
limits: {
|
|
|
|
moran: { timeout: 5000 },
|
|
|
|
kmeans: { timeout: 5000 }
|
|
|
|
}
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
analysisBackend.getAnalysesLimits(user, function (err, result) {
|
2016-10-20 20:02:13 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(result.analyses.moran);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.moran.timeout, 5000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
assert.ok(result.analyses.kmeans);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.kmeans.timeout, 5000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should use limits from redis', function (done) {
|
2016-10-20 20:02:13 +08:00
|
|
|
var self = this;
|
|
|
|
var limits = ['moran', 5000];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
withAnalysesLimits(limits, function (err) {
|
2016-10-20 20:02:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var analysisBackend = new AnalysisBackend(self.metadataBackend);
|
2019-10-22 01:07:24 +08:00
|
|
|
analysisBackend.getAnalysesLimits(user, function (err, result) {
|
2016-10-20 20:02:13 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(result.analyses.moran);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.moran.timeout, 5000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should use limits from redis and configuration, redis takes priority', function (done) {
|
2016-10-20 20:02:13 +08:00
|
|
|
var self = this;
|
|
|
|
var limits = ['moran', 5000];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
withAnalysesLimits(limits, function (err) {
|
2016-10-20 20:02:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-11 01:41:59 +08:00
|
|
|
var analysisBackend = new AnalysisBackend(self.metadataBackend, {
|
|
|
|
limits: {
|
|
|
|
moran: { timeout: 1000 }
|
|
|
|
}
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
analysisBackend.getAnalysesLimits(user, function (err, result) {
|
2016-10-20 20:02:13 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(result.analyses.moran);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.moran.timeout, 5000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should use limits from redis and configuration, defaulting for values not present in redis', function (done) {
|
2016-10-20 20:02:13 +08:00
|
|
|
var self = this;
|
|
|
|
var limits = ['moran', 5000];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
withAnalysesLimits(limits, function (err) {
|
2016-10-20 20:02:13 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-11 01:41:59 +08:00
|
|
|
var analysisBackend = new AnalysisBackend(self.metadataBackend, {
|
|
|
|
limits: {
|
|
|
|
moran: { timeout: 1000 },
|
|
|
|
kmeans: { timeout: 1000 }
|
|
|
|
}
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
analysisBackend.getAnalysesLimits(user, function (err, result) {
|
2016-10-20 20:02:13 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(result.analyses.moran);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.moran.timeout, 5000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
assert.ok(result.analyses.kmeans);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses.kmeans.timeout, 1000);
|
2016-10-20 20:02:13 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should allow to set other limits per analysis via configuration, and keep timeout from redis', function (done) {
|
2016-11-11 01:41:59 +08:00
|
|
|
var self = this;
|
|
|
|
var limits = ['aggregate-intersection', 5000];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
withAnalysesLimits(limits, function (err) {
|
2016-11-11 01:41:59 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var analysisBackend = new AnalysisBackend(self.metadataBackend, {
|
|
|
|
limits: {
|
|
|
|
'aggregate-intersection': { timeout: 10000, maxNumberOfRows: 1e5 }
|
|
|
|
}
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
analysisBackend.getAnalysesLimits(user, function (err, result) {
|
2016-11-11 01:41:59 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(result.analyses['aggregate-intersection']);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.analyses['aggregate-intersection'].timeout, 5000);
|
|
|
|
assert.strictEqual(result.analyses['aggregate-intersection'].maxNumberOfRows, 1e5);
|
2016-11-11 01:41:59 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-10-20 20:02:13 +08:00
|
|
|
});
|