2016-02-01 23:53:28 +08:00
|
|
|
require('../helper');
|
|
|
|
|
|
|
|
var qs = require('querystring');
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
var server = require('../../app/server')();
|
2016-02-01 23:53:28 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
|
|
|
|
describe('query-tables-api', function() {
|
|
|
|
|
2017-06-27 18:58:23 +08:00
|
|
|
beforeEach(function(done) {
|
|
|
|
var tableCacheEnabled = global.settings.tableCacheEnabled || false;
|
|
|
|
if(!tableCacheEnabled) {
|
|
|
|
this.skip("tableCache is disabled");
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
function getCacheStatus(callback) {
|
|
|
|
assert.response(
|
2016-09-15 02:54:24 +08:00
|
|
|
server,
|
2016-02-02 08:16:24 +08:00
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/cachestatus'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
2016-09-26 20:37:40 +08:00
|
|
|
function(err, res) {
|
2016-02-02 08:16:24 +08:00
|
|
|
callback(null, JSON.parse(res.body));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
url: '/api/v1/sql?' + qs.stringify({
|
|
|
|
q: 'SELECT * FROM untitle_table_4'
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
2016-02-01 23:53:28 +08:00
|
|
|
},
|
2016-02-02 08:16:24 +08:00
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
|
|
|
|
var RESPONSE_OK = {
|
|
|
|
status: 200
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should create a key in affected tables cache', function(done) {
|
2016-09-26 20:42:24 +08:00
|
|
|
assert.response(server, request, RESPONSE_OK, function(err) {
|
2016-02-02 08:16:24 +08:00
|
|
|
assert.ok(!err, err);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
2016-03-08 21:50:08 +08:00
|
|
|
assert.equal(cacheStatus.explain.hits, 0);
|
2016-02-02 08:16:24 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
it('should use cache to retrieve affected tables', function(done) {
|
2016-09-26 20:42:24 +08:00
|
|
|
assert.response(server, request, RESPONSE_OK, function(err) {
|
2016-02-02 08:16:24 +08:00
|
|
|
assert.ok(!err, err);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
2016-03-08 21:50:08 +08:00
|
|
|
assert.equal(cacheStatus.explain.hits, 1);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
});
|
|
|
|
});
|
2016-03-11 02:20:56 +08:00
|
|
|
|
|
|
|
it('should skip cache to retrieve affected tables', function(done) {
|
|
|
|
var authenticatedRequest = {
|
|
|
|
url: '/api/v1/sql?' + qs.stringify({
|
|
|
|
q: 'SELECT * FROM untitle_table_4',
|
|
|
|
api_key: '1234'
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
};
|
2016-09-26 20:37:40 +08:00
|
|
|
assert.response(server, authenticatedRequest, RESPONSE_OK, function(err) {
|
2016-03-11 02:20:56 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
|
|
|
assert.equal(cacheStatus.explain.hits, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
});
|