Test for the COPY FROM + disconnect

This commit is contained in:
Rafa de la Torre 2018-06-11 19:17:23 +02:00
parent 66664de286
commit b1073dc401

View File

@ -332,6 +332,9 @@ describe('copy-endpoints db connections', function() {
});
describe('copy-endpoints client disconnection', function() {
// Give it enough time to connect and issue the query but not too much so as to disconnect in the middle of the query
const client_disconnect_timeout = 10;
before(function() {
this.db_pool_size = global.settings.db_pool_size;
global.settings.db_pool_size = 1;
@ -341,8 +344,6 @@ describe('copy-endpoints client disconnection', function() {
global.settings.db_pool_size = this.db_pool_size;
});
it('copy to returns the connection to the pool if the client disconnects', function(done) {
var assertCanReuseConnection = function (done) {
assert.response(server, {
url: '/api/v1/sql?' + querystring.stringify({
@ -357,18 +358,37 @@ describe('copy-endpoints client disconnection', function() {
});
};
it('COPY TO returns the connection to the pool if the client disconnects', function(done) {
assert.response(server, {
url: '/api/v1/sql/copyto?' + querystring.stringify({
q: 'COPY (SELECT * FROM generate_series(1, 100000)) TO STDOUT',
}),
headers: { host: 'vizzuality.cartodb.com' },
method: 'GET',
timeout: 10
}, {}, function(err, res) {
timeout: client_disconnect_timeout
}, {}, function(err) {
// we're expecting a timeout error
assert.ok(err);
assert.ok(err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT');
assertCanReuseConnection(done);
});
});
it('COPY FROM returns the connection to the pool if the client disconnects', function(done) {
assert.response(server, {
url: '/api/v1/sql/copyfrom?' + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)",
}),
headers: { host: 'vizzuality.cartodb.com' },
method: 'POST',
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
timeout: client_disconnect_timeout
}, {}, function(err) {
// we're expecting a timeout error
assert.ok(err);
assert.ok(err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT');
assertCanReuseConnection(done);
});
});
});