2014-01-31 17:55:30 +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');
|
|
|
|
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var step = require('step');
|
|
|
|
|
|
|
|
describe('timeout', function() {
|
2014-01-31 17:55:30 +08:00
|
|
|
|
|
|
|
// See https://github.com/CartoDB/CartoDB-SQL-API/issues/128
|
2015-05-13 17:21:44 +08:00
|
|
|
it('after configured milliseconds', function(done){
|
2014-01-31 17:55:30 +08:00
|
|
|
var testTimeout = 10;
|
|
|
|
//console.log("settings:"); console.dir(global.settings);
|
|
|
|
var timeoutBackup = global.settings.node_socket_timeout;
|
|
|
|
global.settings.node_socket_timeout = testTimeout;
|
2016-09-15 02:54:24 +08:00
|
|
|
var server = require('../../app/server')();
|
2015-05-13 17:21:44 +08:00
|
|
|
step(
|
2014-01-31 17:55:30 +08:00
|
|
|
function sendLongQuery() {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2014-01-31 17:55:30 +08:00
|
|
|
url: '/api/v1/sql?q=SELECT+count(*)+FROM+generate_series(1,100000)',
|
|
|
|
method: 'GET',
|
|
|
|
headers: {host: 'vizzuality.localhost' }
|
2016-09-26 20:37:40 +08:00
|
|
|
},{}, this);
|
2014-01-31 17:55:30 +08:00
|
|
|
},
|
2015-05-13 17:21:44 +08:00
|
|
|
function checkResponse(err/*, res*/) {
|
2014-01-31 17:55:30 +08:00
|
|
|
assert.ok(err);
|
|
|
|
assert.ok(err.message.match(/hang up/), err);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
global.settings.node_socket_timeout = timeoutBackup;
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: check that the query is interrupted on timeout!
|
|
|
|
//See #129
|
|
|
|
|
|
|
|
});
|