2016-03-19 01:12:01 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Requires the database and tables setup in config/environments/test.js to exist
|
|
|
|
* Ensure the user is present in the pgbouncer auth file too
|
|
|
|
* TODO: Add OAuth tests.
|
|
|
|
*
|
|
|
|
* To run this test, ensure that cartodb_test_user_1_db metadata exists
|
|
|
|
* in Redis for the vizzuality.cartodb.com domain
|
|
|
|
*
|
|
|
|
* SELECT 5
|
|
|
|
* HSET rails:users:vizzuality id 1
|
|
|
|
* HSET rails:users:vizzuality database_name cartodb_test_user_1_db
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
require('../helper');
|
|
|
|
|
|
|
|
var app = require(global.settings.app_root + '/app/app')();
|
|
|
|
var assert = require('../support/assert');
|
|
|
|
var querystring = require('querystring');
|
2016-07-07 20:14:46 +08:00
|
|
|
var redisConfig = {
|
2016-03-19 01:12:01 +08:00
|
|
|
host: global.settings.redis_host,
|
|
|
|
port: global.settings.redis_port,
|
|
|
|
max: global.settings.redisPool,
|
|
|
|
idleTimeoutMillis: global.settings.redisIdleTimeoutMillis,
|
|
|
|
reapIntervalMillis: global.settings.redisReapIntervalMillis
|
2016-07-07 20:14:46 +08:00
|
|
|
};
|
|
|
|
var metadataBackend = require('cartodb-redis')(redisConfig);
|
2016-03-19 01:12:01 +08:00
|
|
|
var batchFactory = require('../../batch');
|
|
|
|
|
2016-05-16 07:22:47 +08:00
|
|
|
describe('Use case 10: cancel and modify a done multiquery job', function () {
|
2016-07-21 01:50:28 +08:00
|
|
|
this.timeout(30000);
|
2016-03-19 01:12:01 +08:00
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
var batch = batchFactory(metadataBackend, redisConfig);
|
2016-03-19 01:12:01 +08:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
batch.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
batch.stop();
|
|
|
|
batch.drain(function () {
|
|
|
|
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var doneJob = {};
|
|
|
|
|
|
|
|
it('Step 1, should create a multiquery job', function (done) {
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: [
|
|
|
|
"SELECT * FROM untitle_table_4",
|
|
|
|
"SELECT * FROM untitle_table_4",
|
|
|
|
"SELECT * FROM untitle_table_4"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res) {
|
|
|
|
doneJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Step 2, multiquery job should be done', function (done) {
|
|
|
|
var interval = setInterval(function () {
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v2/sql/job/' + doneJob.job_id + '?api_key=1234',
|
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res) {
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === "done") {
|
|
|
|
clearInterval(interval);
|
|
|
|
done();
|
|
|
|
} else if (job.status === "failed" || job.status === "cancelled") {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
} else {
|
|
|
|
console.log('Job ' + job.job_id + ' is ' + job.status + ', expecting to be done');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Step 3, cancel a done multiquery job should give an error', function (done){
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v2/sql/job/' + doneJob.job_id + '?api_key=1234',
|
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var errors = JSON.parse(res.body);
|
2016-05-16 07:22:47 +08:00
|
|
|
assert.equal(errors.error[0], "Cannot set status from done to cancelled");
|
2016-03-19 01:12:01 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Step 4, modify a done multiquery job should give an error', function (done){
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v2/sql/job/' + doneJob.job_id + '?api_key=1234',
|
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({
|
2016-05-16 07:22:47 +08:00
|
|
|
query: [
|
|
|
|
"SELECT * FROM untitle_table_4",
|
|
|
|
"SELECT * FROM untitle_table_4"
|
|
|
|
]
|
2016-03-19 01:12:01 +08:00
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var errors = JSON.parse(res.body);
|
|
|
|
assert.equal(errors.error[0], "Job is not pending, it cannot be updated");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|