2016-05-16 19:49:56 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2016-05-20 20:42:53 +08:00
|
|
|
var assert = require('../support/assert');
|
2016-07-22 23:05:01 +08:00
|
|
|
var redisUtils = require('../support/redis_utils');
|
2016-09-15 02:54:24 +08:00
|
|
|
var server = require('../../app/server')();
|
2016-05-20 20:42:53 +08:00
|
|
|
var querystring = require('qs');
|
2016-07-07 20:14:46 +08:00
|
|
|
var redisConfig = {
|
2016-05-16 19:49:56 +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-05-17 07:00:27 +08:00
|
|
|
var batchFactory = require('../../batch');
|
|
|
|
var jobStatus = require('../../batch/job_status');
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('Batch API fallback job', function () {
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-06-29 19:56:45 +08:00
|
|
|
function validateExpectedResponse(actual, expected) {
|
|
|
|
actual.query.forEach(function(actualQuery, index) {
|
|
|
|
var expectedQuery = expected.query[index];
|
|
|
|
assert.ok(expectedQuery);
|
|
|
|
Object.keys(expectedQuery).forEach(function(expectedKey) {
|
|
|
|
assert.equal(actualQuery[expectedKey], expectedQuery[expectedKey]);
|
|
|
|
});
|
|
|
|
var propsToCheckDate = ['started_at', 'ended_at'];
|
|
|
|
propsToCheckDate.forEach(function(propToCheckDate) {
|
|
|
|
if (actualQuery.hasOwnProperty(propToCheckDate)) {
|
|
|
|
assert.ok(new Date(actualQuery[propToCheckDate]));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(actual.onsuccess, expected.onsuccess);
|
|
|
|
assert.equal(actual.onerror, expected.onerror);
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
var batch = batchFactory(metadataBackend, redisConfig);
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-07-22 20:27:18 +08:00
|
|
|
before(function (done) {
|
2016-05-17 07:00:27 +08:00
|
|
|
batch.start();
|
2016-07-22 20:27:18 +08:00
|
|
|
batch.on('ready', done);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
after(function (done) {
|
|
|
|
batch.stop();
|
2016-07-22 23:05:01 +08:00
|
|
|
redisUtils.clean('batch:*', done);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onsuccess" on first query should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
2016-05-16 19:49:56 +08:00
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be running'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onerror" on first query should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done){
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
2016-05-26 23:37:37 +08:00
|
|
|
"fallback_status": "skipped"
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onerror" on first query should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* query should fail */",
|
2016-05-17 07:00:27 +08:00
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done){
|
|
|
|
var expectedQuery = {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 1',
|
2016-05-23 21:05:14 +08:00
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'done',
|
2016-05-19 22:58:14 +08:00
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onsuccess" on first query should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* query should fail */",
|
2016-05-17 07:00:27 +08:00
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be failed', function (done){
|
|
|
|
var expectedQuery = {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1',
|
2016-05-23 21:05:14 +08:00
|
|
|
status: 'failed',
|
2016-05-26 23:37:37 +08:00
|
|
|
fallback_status: 'skipped',
|
2016-05-19 22:58:14 +08:00
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
|
|
|
|
describe('"onsuccess" should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"status": "done"
|
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.DONE && job.fallback_status === jobStatus.DONE) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onsuccess" should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* query should fail */",
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM nonexistent_table /* query should fail */',
|
|
|
|
status: 'failed',
|
|
|
|
failed_reason: 'relation "nonexistent_table" does not exist'
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
2016-05-19 22:58:14 +08:00
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 1'
|
2016-05-17 07:00:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-26 23:37:37 +08:00
|
|
|
if (job.status === jobStatus.FAILED && job.fallback_status === jobStatus.SKIPPED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be pending'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
|
|
|
|
describe('"onerror" should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* query should fail */"
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
2016-05-19 22:58:14 +08:00
|
|
|
"query": "SELECT * FROM nonexistent_table /* query should fail */",
|
|
|
|
"status": "failed",
|
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.FAILED && job.fallback_status === jobStatus.DONE) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-05-23 21:05:14 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
2016-05-20 20:42:53 +08:00
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onerror" should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
}],
|
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"status": "done"
|
|
|
|
}],
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-26 23:37:37 +08:00
|
|
|
if (job.status === jobStatus.DONE && job.fallback_status === jobStatus.SKIPPED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
2016-05-23 21:05:14 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
2016-05-20 20:42:53 +08:00
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
|
2016-05-18 00:51:02 +08:00
|
|
|
describe('"onsuccess" & "onsuccess" on query should be triggered', function () {
|
2016-05-17 07:00:27 +08:00
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-17 07:00:27 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.DONE && job.fallback_status === jobStatus.DONE) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
describe('"onsuccess" for each query should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-17 07:00:27 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 3"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
|
2016-05-17 07:00:27 +08:00
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-17 07:00:27 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-17 07:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('"onsuccess" for each query should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-18 00:51:02 +08:00
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 3"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be failed', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
2016-05-19 22:58:14 +08:00
|
|
|
"query": "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-18 00:51:02 +08:00
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "failed",
|
2016-05-26 23:37:37 +08:00
|
|
|
"fallback_status": "skipped",
|
2016-05-19 22:58:14 +08:00
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-26 23:37:37 +08:00
|
|
|
"status": "skipped",
|
|
|
|
"fallback_status": "skipped"
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('"onsuccess" for second query should not be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 1"
|
|
|
|
}, {
|
2016-05-19 22:58:14 +08:00
|
|
|
query: "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-18 00:51:02 +08:00
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 3"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be failed', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
2016-05-19 22:58:14 +08:00
|
|
|
"query": "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-18 00:51:02 +08:00
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "failed",
|
2016-05-26 23:37:37 +08:00
|
|
|
"fallback_status": "skipped",
|
2016-05-19 22:58:14 +08:00
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-17 07:00:27 +08:00
|
|
|
}, 50);
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
2016-05-26 23:37:37 +08:00
|
|
|
describe('"onerror" should not be triggered for any query and "skipped"', function () {
|
2016-05-25 23:00:27 +08:00
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-25 23:00:27 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
onerror: "SELECT * FROM untitle_table_4 limit 4"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be failed', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
2016-05-26 23:37:37 +08:00
|
|
|
fallback_status: 'skipped'
|
2016-05-25 23:00:27 +08:00
|
|
|
}, {
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'done',
|
2016-05-26 23:37:37 +08:00
|
|
|
fallback_status: 'skipped'
|
2016-05-25 23:00:27 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-25 23:00:27 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-25 23:00:27 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
2016-05-26 23:37:37 +08:00
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-01 16:39:01 +08:00
|
|
|
describe('"onsuccess" should be "skipped"', function () {
|
2016-05-26 23:37:37 +08:00
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1, /* should fail */",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be failed', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */',
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'skipped',
|
|
|
|
failed_reason: 'syntax error at end of input'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-26 23:37:37 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('"onsuccess" should not be triggered and "skipped"', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1, /* should fail */",
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be failed', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1, /* should fail */',
|
|
|
|
status: 'failed',
|
|
|
|
failed_reason: 'syntax error at end of input'
|
|
|
|
}],
|
|
|
|
onsuccess: 'SELECT * FROM untitle_table_4 limit 2'
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.FAILED && job.fallback_status === jobStatus.SKIPPED) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-26 23:37:37 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
2016-05-25 23:00:27 +08:00
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
|
|
|
|
describe('"onsuccess" for first query should fail', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-19 22:58:14 +08:00
|
|
|
onsuccess: "SELECT * FROM nonexistent_table /* should fail */"
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 3"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
2016-05-19 22:58:14 +08:00
|
|
|
"onsuccess": "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "failed",
|
2016-05-19 22:58:14 +08:00
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('"onsuccess" for second query should fail', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-19 22:58:14 +08:00
|
|
|
onsuccess: "SELECT * FROM nonexistent_table /* should fail */"
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 2",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-19 22:58:14 +08:00
|
|
|
"onsuccess": "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "failed",
|
2016-05-19 22:58:14 +08:00
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-18 00:51:02 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
|
|
|
if (job.status === jobStatus.DONE) {
|
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('"onsuccess" for job & "onsuccess" for each query should be triggered', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 4"
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 5"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 2",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 4",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 5"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.DONE && job.fallback_status === jobStatus.DONE) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('"onsuccess" for job & "onsuccess" for each query should be triggered ' +
|
|
|
|
'(even second "onsuccess" fails job should be done)', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 00:51:02 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
}, {
|
|
|
|
query: "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-19 22:58:14 +08:00
|
|
|
onsuccess: "SELECT * FROM nonexistent_table /* should fail */"
|
2016-05-18 00:51:02 +08:00
|
|
|
}],
|
|
|
|
onsuccess: "SELECT * FROM untitle_table_4 limit 5"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be done', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 2",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "done"
|
2016-05-18 00:51:02 +08:00
|
|
|
}, {
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
2016-05-19 22:58:14 +08:00
|
|
|
"onsuccess": "SELECT * FROM nonexistent_table /* should fail */",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "failed",
|
2016-05-19 22:58:14 +08:00
|
|
|
"failed_reason": 'relation "nonexistent_table" does not exist'
|
2016-05-18 00:51:02 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT * FROM untitle_table_4 limit 5"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.DONE && job.fallback_status === jobStatus.DONE) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.FAILED || job.status === jobStatus.CANCELLED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be done'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 00:51:02 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-18 19:25:08 +08:00
|
|
|
describe('"onsuccess" for job & "onsuccess" for each query should not be triggered ' +
|
|
|
|
' because it has been cancelled', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 19:25:08 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT pg_sleep(3)",
|
|
|
|
onsuccess: "SELECT pg_sleep(0)"
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT pg_sleep(0)"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be running', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT pg_sleep(3)",
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "running",
|
|
|
|
"fallback_status": "pending"
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.status === jobStatus.RUNNING && job.fallback_status === jobStatus.PENDING) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.DONE ||
|
|
|
|
job.status === jobStatus.FAILED ||
|
|
|
|
job.status === jobStatus.CANCELLED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-05-26 23:37:37 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be running'));
|
2016-05-20 20:42:53 +08:00
|
|
|
}
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be cancelled', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT pg_sleep(3)",
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "cancelled",
|
2016-05-26 23:37:37 +08:00
|
|
|
"fallback_status": "skipped"
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)"
|
|
|
|
};
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-26 23:37:37 +08:00
|
|
|
if (job.status === jobStatus.CANCELLED && job.fallback_status === jobStatus.SKIPPED) {
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.FAILED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be cancelled'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('first "onsuccess" should be triggered and it will be cancelled', function () {
|
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
2016-05-18 19:25:08 +08:00
|
|
|
query: {
|
|
|
|
query: [{
|
|
|
|
query: "SELECT pg_sleep(0)",
|
|
|
|
onsuccess: "SELECT pg_sleep(3)"
|
|
|
|
}],
|
|
|
|
onsuccess: "SELECT pg_sleep(0)"
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 20:42:53 +08:00
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('job "onsuccess" should be running', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT pg_sleep(0)",
|
|
|
|
"onsuccess": "SELECT pg_sleep(3)",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "running"
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)"
|
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-23 21:05:14 +08:00
|
|
|
if (job.query.query[0].status === jobStatus.DONE &&
|
|
|
|
job.query.query[0].fallback_status === jobStatus.RUNNING) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.query.query[0].status === jobStatus.DONE ||
|
|
|
|
job.query.query[0].status === jobStatus.FAILED ||
|
|
|
|
job.query.query[0].status === jobStatus.CANCELLED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
clearInterval(interval);
|
|
|
|
done(new Error('Job ' + job.job_id + ' is ' +
|
|
|
|
job.query.query[0].status +
|
|
|
|
', expected to be running'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should be cancelled', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
"query": [{
|
|
|
|
"query": "SELECT pg_sleep(0)",
|
|
|
|
"onsuccess": "SELECT pg_sleep(3)",
|
2016-05-23 21:05:14 +08:00
|
|
|
"status": "done",
|
|
|
|
"fallback_status": "cancelled"
|
2016-05-18 19:25:08 +08:00
|
|
|
}],
|
|
|
|
"onsuccess": "SELECT pg_sleep(0)"
|
|
|
|
};
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-20 20:42:53 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-05-26 23:37:37 +08:00
|
|
|
if (job.status === jobStatus.CANCELLED && job.fallback_status === jobStatus.SKIPPED) {
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-20 20:42:53 +08:00
|
|
|
done();
|
2016-05-23 21:05:14 +08:00
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.FAILED) {
|
2016-05-20 20:42:53 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be cancelled'));
|
|
|
|
}
|
|
|
|
});
|
2016-05-18 19:25:08 +08:00
|
|
|
});
|
|
|
|
});
|
2016-05-26 23:37:37 +08:00
|
|
|
|
2016-07-01 00:16:52 +08:00
|
|
|
describe('should fail first "onerror" and job "onerror" and skip the other ones', function () {
|
2016-05-26 23:37:37 +08:00
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
"query": {
|
|
|
|
"query": [{
|
2016-07-01 00:16:52 +08:00
|
|
|
"query": "SELECT * FROM atm_madrid limit 1, should fail",
|
|
|
|
"onerror": "SELECT * FROM atm_madrid limit 2"
|
2016-05-26 23:37:37 +08:00
|
|
|
}, {
|
2016-07-01 00:16:52 +08:00
|
|
|
"query": "SELECT * FROM atm_madrid limit 3",
|
|
|
|
"onerror": "SELECT * FROM atm_madrid limit 4"
|
2016-05-26 23:37:37 +08:00
|
|
|
}],
|
2016-07-01 00:16:52 +08:00
|
|
|
"onerror": "SELECT * FROM atm_madrid limit 5"
|
2016-05-26 23:37:37 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should fail', function (done) {
|
|
|
|
var expectedQuery = {
|
2016-07-01 00:16:52 +08:00
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM atm_madrid limit 1, should fail',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 2',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'failed',
|
|
|
|
failed_reason: 'relation "atm_madrid" does not exist'
|
|
|
|
}, {
|
|
|
|
query: 'SELECT * FROM atm_madrid limit 3',
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 4',
|
|
|
|
status: 'skipped',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}],
|
|
|
|
onerror: 'SELECT * FROM atm_madrid limit 5'
|
2016-05-26 23:37:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-07-01 00:16:52 +08:00
|
|
|
if (job.status === jobStatus.FAILED && job.fallback_status === jobStatus.FAILED) {
|
2016-05-26 23:37:37 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-26 23:37:37 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
2016-06-03 00:02:25 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
2016-05-26 23:37:37 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-01 00:16:52 +08:00
|
|
|
describe('should run first "onerror" and job "onerror" and skip the other ones', function () {
|
2016-05-26 23:37:37 +08:00
|
|
|
var fallbackJob = {};
|
|
|
|
|
|
|
|
it('should create a job', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
"query": {
|
|
|
|
"query": [{
|
2016-07-01 00:16:52 +08:00
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1, should fail",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 2"
|
2016-05-26 23:37:37 +08:00
|
|
|
}, {
|
2016-07-01 00:16:52 +08:00
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 4"
|
2016-05-26 23:37:37 +08:00
|
|
|
}],
|
2016-07-01 00:16:52 +08:00
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 5"
|
2016-05-26 23:37:37 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 201
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
fallbackJob = JSON.parse(res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('job should fail', function (done) {
|
|
|
|
var expectedQuery = {
|
2016-07-01 00:16:52 +08:00
|
|
|
"query": [
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1, should fail",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 2",
|
|
|
|
"status": "failed",
|
|
|
|
"fallback_status": "done",
|
|
|
|
"failed_reason": "LIMIT #,# syntax is not supported"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 4",
|
|
|
|
"status": "skipped",
|
|
|
|
"fallback_status": "skipped"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 5"
|
2016-05-26 23:37:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2016-05-26 23:37:37 +08:00
|
|
|
url: '/api/v2/sql/job/' + fallbackJob.job_id + '?api_key=1234&',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
'host': 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function (res, err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var job = JSON.parse(res.body);
|
2016-07-01 00:16:52 +08:00
|
|
|
if (job.status === jobStatus.FAILED && job.fallback_status === jobStatus.DONE) {
|
2016-05-26 23:37:37 +08:00
|
|
|
clearInterval(interval);
|
2016-06-29 19:56:45 +08:00
|
|
|
validateExpectedResponse(job.query, expectedQuery);
|
2016-05-26 23:37:37 +08:00
|
|
|
done();
|
|
|
|
} else if (job.status === jobStatus.DONE || job.status === jobStatus.CANCELLED) {
|
|
|
|
clearInterval(interval);
|
2016-06-03 00:02:25 +08:00
|
|
|
done(new Error('Job ' + job.job_id + ' is ' + job.status + ', expected to be failed'));
|
2016-05-26 23:37:37 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
2016-05-16 19:49:56 +08:00
|
|
|
});
|