Windshaft-cartodb/test/integration/analysis-backend-limits-test.js

172 lines
5.3 KiB
JavaScript
Raw Normal View History

'use strict';
var testHelper = require('../support/test-helper');
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');
2019-10-22 01:07:24 +08:00
describe('analysis-backend limits', function () {
var redisClient;
var keysToDelete;
var user = 'localhost';
2019-10-22 01:07:24 +08:00
beforeEach(function () {
2020-12-16 23:32:32 +08:00
redisClient = redis.createClient(
{
port: global.environment.redis.port,
host: global.environment.redis.host
});
keysToDelete = {};
var redisPool = new RedisPool(global.environment.redis);
2019-10-22 01:07:24 +08:00
this.metadataBackend = cartodbRedis({ pool: redisPool });
});
2019-10-22 01:07:24 +08:00
afterEach(function (done) {
redisClient.quit(function () {
testHelper.deleteRedisKeys(keysToDelete, done);
});
});
2019-10-22 01:07:24 +08:00
function withAnalysesLimits (limits, callback) {
redisClient.SELECT(5, function (err) {
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) {
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) {
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) {
assert.ok(!err, err);
assert.ok(result.analyses.moran);
assert.strictEqual(result.analyses.moran.timeout, 5000);
assert.ok(result.analyses.kmeans);
assert.strictEqual(result.analyses.kmeans.timeout, 5000);
done();
});
});
2019-10-22 01:07:24 +08:00
it('should use limits from redis', function (done) {
var self = this;
var limits = ['moran', 5000];
2019-10-22 01:07:24 +08:00
withAnalysesLimits(limits, function (err) {
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) {
assert.ok(!err, err);
assert.ok(result.analyses.moran);
assert.strictEqual(result.analyses.moran.timeout, 5000);
done();
});
});
});
2019-10-22 01:07:24 +08:00
it('should use limits from redis and configuration, redis takes priority', function (done) {
var self = this;
var limits = ['moran', 5000];
2019-10-22 01:07:24 +08:00
withAnalysesLimits(limits, function (err) {
if (err) {
return done(err);
}
var analysisBackend = new AnalysisBackend(self.metadataBackend, {
limits: {
moran: { timeout: 1000 }
}
});
2019-10-22 01:07:24 +08:00
analysisBackend.getAnalysesLimits(user, function (err, result) {
assert.ok(!err, err);
assert.ok(result.analyses.moran);
assert.strictEqual(result.analyses.moran.timeout, 5000);
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) {
var self = this;
var limits = ['moran', 5000];
2019-10-22 01:07:24 +08:00
withAnalysesLimits(limits, function (err) {
if (err) {
return done(err);
}
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) {
assert.ok(!err, err);
assert.ok(result.analyses.moran);
assert.strictEqual(result.analyses.moran.timeout, 5000);
assert.ok(result.analyses.kmeans);
assert.strictEqual(result.analyses.kmeans.timeout, 1000);
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) {
var self = this;
var limits = ['aggregate-intersection', 5000];
2019-10-22 01:07:24 +08:00
withAnalysesLimits(limits, function (err) {
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) {
assert.ok(!err, err);
assert.ok(result.analyses['aggregate-intersection']);
assert.strictEqual(result.analyses['aggregate-intersection'].timeout, 5000);
assert.strictEqual(result.analyses['aggregate-intersection'].maxNumberOfRows, 1e5);
done();
});
});
});
});