More eslint errors

This commit is contained in:
Daniel García Aubert 2019-12-26 16:57:24 +01:00
parent 2e8c0bdbdd
commit 90bdb6d487
7 changed files with 52 additions and 30 deletions

View File

@ -6,24 +6,24 @@ var assert = require('../support/assert');
var step = require('step');
var net = require('net');
var sql_server_port = 5540;
var sql_server = net.createServer(function (c) {
var sqlServerPort = 5540;
var sqlServer = net.createServer(function (c) {
c.destroy();
sql_server.close(function () {
sqlServer.close(function () {
});
});
describe('backend crash', function () {
before(function (done) {
sql_server.listen(sql_server_port, done);
sqlServer.listen(sqlServerPort, done);
});
// See https://github.com/CartoDB/CartoDB-SQL-API/issues/135
it('does not hang server', function (done) {
var db_host_backup = global.settings.db_host;
var db_port_backup = global.settings.db_port;
var dbHostBackup = global.settings.db_host;
var dbPortBackup = global.settings.db_port;
global.settings.db_host = 'localhost';
global.settings.db_port = sql_server_port;
global.settings.db_port = sqlServerPort;
var server = require('../../lib/server')();
step(
function sendQuery () {
@ -59,17 +59,17 @@ describe('backend crash', function () {
return null;
},
function finish (err) {
global.settings.db_host = db_host_backup;
global.settings.db_port = db_port_backup;
global.settings.db_host = dbHostBackup;
global.settings.db_port = dbPortBackup;
done(err);
}
);
});
after(function (done) {
// be sure the sql_server is closed
if (sql_server.listening) {
return sql_server.close(done);
// be sure the sqlServer is closed
if (sqlServer.listening) {
return sqlServer.close(done);
}
done();

View File

@ -7,7 +7,7 @@ var BatchTestClient = require('../../support/batch-test-client');
var JobStatus = require('../../../lib/batch/job-status');
var redisUtils = require('../../support/redis-utils');
var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() });
const db_utils = require('../../support/db_utils');
const dbUtils = require('../../support/db_utils');
describe('batch query statement_timeout limit', function () {
before(function (done) {
@ -16,14 +16,14 @@ describe('batch query statement_timeout limit', function () {
global.settings.batch_query_timeout = 15000;
metadataBackend.redisCmd(5, 'HMSET', ['limits:batch:vizzuality', 'timeout', 100], done);
});
before(db_utils.resetPgBouncerConnections);
before(dbUtils.resetPgBouncerConnections);
after(function (done) {
global.settings.batch_query_timeout = this.batchQueryTimeout;
redisUtils.clean('limits:batch:*', function () {
this.batchTestClient.drain(done);
}.bind(this));
});
after(db_utils.resetPgBouncerConnections);
after(dbUtils.resetPgBouncerConnections);
function jobPayload (query) {
return {

View File

@ -52,6 +52,7 @@ describe('job query limit', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: [expectedErrorMessage(queryTooLong)] });
done();
@ -69,6 +70,7 @@ describe('job query limit', function () {
}, {
status: 201
}, function (err, res) {
assert.ifError(err);
var job = JSON.parse(res.body);
assert.ok(job.job_id);
done();
@ -87,6 +89,7 @@ describe('job query limit', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: [expectedErrorMessage(queries)] });
done();
@ -113,6 +116,7 @@ describe('job query limit', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: [expectedErrorMessage(fallbackQueries)] });
done();

View File

@ -39,6 +39,7 @@ describe('job module', function () {
}, {
status: 201
}, function (err, res) {
assert.ifError(err);
job = JSON.parse(res.body);
assert.deepStrictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
assert.ok(job.job_id);
@ -58,6 +59,7 @@ describe('job module', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: ['You must indicate a valid SQL'] });
done();
@ -75,6 +77,7 @@ describe('job module', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: ['You must indicate a valid SQL'] });
done();
@ -92,6 +95,7 @@ describe('job module', function () {
}, {
status: 401
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: ['Unauthorized'] });
done();
@ -109,6 +113,7 @@ describe('job module', function () {
}, {
status: 404
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, {
error: [
@ -128,6 +133,7 @@ describe('job module', function () {
}, {
status: 200
}, function (err, res) {
assert.ifError(err);
var jobGot = JSON.parse(res.body);
assert.deepStrictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
assert.strictEqual(jobGot.query, 'SELECT * FROM untitle_table_4');
@ -144,6 +150,7 @@ describe('job module', function () {
}, {
status: 401
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: ['Unauthorized'] });
done();
@ -158,6 +165,7 @@ describe('job module', function () {
}, {
status: 400
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, {
error: ['Job with id irrelevantJob not found']
@ -174,6 +182,7 @@ describe('job module', function () {
}, {
status: 200
}, function (err, res) {
assert.ifError(err);
var jobCancelled = JSON.parse(res.body);
assert.deepStrictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
assert.strictEqual(jobCancelled.job_id, job.job_id);
@ -192,6 +201,7 @@ describe('job module', function () {
}, {
status: 401
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, { error: ['Unauthorized'] });
done();
@ -206,6 +216,7 @@ describe('job module', function () {
}, {
status: 404
}, function (err, res) {
assert.ifError(err);
var error = JSON.parse(res.body);
assert.deepStrictEqual(error, {
error: [

View File

@ -82,6 +82,7 @@ describe('multiple batch clients and users, job query order', function () {
return done(err);
}
jobResultB1.getStatus(function (err, jobB1) {
assert.ifError(err);
assert.strictEqual(jobA1.status, JobStatus.DONE);
assert.strictEqual(jobA2.status, JobStatus.DONE);
assert.strictEqual(jobB1.status, JobStatus.DONE);

View File

@ -33,6 +33,7 @@ describe('Use cases', function () {
assert.strictEqual(job.status, JobStatus.DONE);
jobResult.tryCancel(function (err, body) {
assert.ifError(err);
assert.strictEqual(body.error[0], 'Cannot set status from done to cancelled');
done();
});
@ -65,6 +66,7 @@ describe('Use cases', function () {
assert.strictEqual(job.status, JobStatus.CANCELLED);
jobResult.tryCancel(function (err, body) {
assert.ifError(err);
assert.strictEqual(body.error[0], 'Cannot set status from cancelled to cancelled');
done();
});
@ -179,6 +181,7 @@ describe('Use cases', function () {
assert.strictEqual(job.status, JobStatus.CANCELLED);
jobResult.tryCancel(function (err, body) {
assert.ifError(err);
assert.strictEqual(body.error[0], 'Cannot set status from cancelled to cancelled');
done();
});

View File

@ -6,6 +6,7 @@ const fs = require('fs');
const querystring = require('querystring');
const assert = require('../support/assert');
const os = require('os');
const path = require('path');
const { Client } = require('pg');
const request = require('request');
@ -66,7 +67,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err, res) {
@ -83,7 +84,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY unexisting_table (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err, res) {
@ -91,7 +92,7 @@ describe('copy-endpoints', function () {
assert.deepStrictEqual(
JSON.parse(res.body),
{
error: ['relation \"unexisting_table\" does not exist']
error: ['relation "unexisting_table" does not exist']
}
);
done();
@ -120,7 +121,7 @@ describe('copy-endpoints', function () {
it('should fail with copyfrom endpoint and without q', function (done) {
assert.response(server, {
url: '/api/v1/sql/copyfrom',
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err, res) {
@ -140,7 +141,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err) {
@ -171,7 +172,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: {
host: 'vizzuality.cartodb.com'
},
@ -227,7 +228,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv.gz'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv.gz')),
headers: {
host: 'vizzuality.cartodb.com',
'content-encoding': 'gzip'
@ -247,7 +248,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: {
host: 'vizzuality.cartodb.com',
'content-encoding': 'gzip'
@ -282,7 +283,7 @@ describe('copy-endpoints', function () {
q: `COPY copy_endpoints_test (id, name)
FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)`
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
},
@ -345,7 +346,7 @@ describe('copy-endpoints', function () {
q: `COPY copy_endpoints_test (id, name)
FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)`
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err, res) {
@ -384,7 +385,7 @@ describe('copy-endpoints', function () {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {}, function (err) {
@ -462,7 +463,7 @@ describe('copy-endpoints', function () {
url: `http://${address}:${port}/api/v1/sql/copyfrom?${query}`,
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST',
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv')
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv'))
};
const req = request(options);
@ -498,7 +499,7 @@ describe('copy-endpoints', function () {
q: `COPY copy_endpoints_test (id, name)
FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)`
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {
@ -564,13 +565,14 @@ describe('copy-endpoints', function () {
q: `COPY copy_endpoints_test (id, name)
FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)`
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {
status: 400,
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}, function (err, res) {
assert.ifError(err);
const response = JSON.parse(res.body);
assert.deepStrictEqual(response, { error: ['DB Quota exceeded'] });
@ -615,13 +617,14 @@ describe('copy-endpoints', function () {
q: `COPY copy_endpoints_test (id, name)
FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)`
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
data: fs.createReadStream(path.join(__dirname, '/../support/csv/copy_test_table.csv')),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST'
}, {
status: 400,
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}, function (err, res) {
assert.ifError(err);
const response = JSON.parse(res.body);
assert.deepStrictEqual(response, { error: ['COPY FROM maximum POST size of 10 bytes exceeded'] });