Helper to reset pgbouncer connections #521
This sends a PAUSE and RESUME to pgbouncer (in case there's one) before and after executing tests, to make sure new connections are established in the tests. This may be especially important when role or session settings are modified in the DB (same happens in prod, BTW).
This commit is contained in:
parent
6eeb949583
commit
20d1db78dc
@ -5,6 +5,7 @@ var BatchTestClient = require('../../support/batch-test-client');
|
|||||||
var JobStatus = require('../../../batch/job_status');
|
var JobStatus = require('../../../batch/job_status');
|
||||||
var redisUtils = require('../../support/redis_utils');
|
var redisUtils = require('../../support/redis_utils');
|
||||||
var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() });
|
var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() });
|
||||||
|
const db_utils = require('../../support/db_utils');
|
||||||
|
|
||||||
describe('batch query statement_timeout limit', function() {
|
describe('batch query statement_timeout limit', function() {
|
||||||
|
|
||||||
@ -14,13 +15,14 @@ describe('batch query statement_timeout limit', function() {
|
|||||||
global.settings.batch_query_timeout = 15000;
|
global.settings.batch_query_timeout = 15000;
|
||||||
metadataBackend.redisCmd(5, 'HMSET', ['limits:batch:vizzuality', 'timeout', 100], done);
|
metadataBackend.redisCmd(5, 'HMSET', ['limits:batch:vizzuality', 'timeout', 100], done);
|
||||||
});
|
});
|
||||||
|
before(db_utils.resetPgBouncerConnections);
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
global.settings.batch_query_timeout = this.batchQueryTimeout;
|
global.settings.batch_query_timeout = this.batchQueryTimeout;
|
||||||
redisUtils.clean('limits:batch:*', function() {
|
redisUtils.clean('limits:batch:*', function() {
|
||||||
this.batchTestClient.drain(done);
|
this.batchTestClient.drain(done);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
});
|
});
|
||||||
|
after(db_utils.resetPgBouncerConnections);
|
||||||
|
|
||||||
function jobPayload(query) {
|
function jobPayload(query) {
|
||||||
return {
|
return {
|
||||||
|
@ -4,9 +4,13 @@ require('../../support/assert');
|
|||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
const db_utils = require('../../support/db_utils');
|
||||||
|
|
||||||
describe('timeout', function () {
|
describe('timeout', function () {
|
||||||
describe('export database', function () {
|
describe('export database', function () {
|
||||||
|
before(db_utils.resetPgBouncerConnections);
|
||||||
|
after(db_utils.resetPgBouncerConnections);
|
||||||
|
|
||||||
const databaseTimeoutQuery = `
|
const databaseTimeoutQuery = `
|
||||||
select
|
select
|
||||||
ST_SetSRID(ST_Point(0, 0), 4326) as the_geom,
|
ST_SetSRID(ST_Point(0, 0), 4326) as the_geom,
|
||||||
|
37
test/support/db_utils.js
Normal file
37
test/support/db_utils.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { Client } = require('pg');
|
||||||
|
|
||||||
|
const dbConfig = {
|
||||||
|
db_user: process.env.PGUSER || 'postgres',
|
||||||
|
db_host: global.settings.db_host,
|
||||||
|
db_port: global.settings.db_port,
|
||||||
|
db_batch_port: global.settings.db_batch_port
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.resetPgBouncerConnections = function (callback) {
|
||||||
|
// We assume there's no pgbouncer if db_port === db_batch_port
|
||||||
|
if (dbConfig.db_port === dbConfig.db_batch_port) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
database: 'pgbouncer',
|
||||||
|
user: dbConfig.db_user,
|
||||||
|
host: dbConfig.db_host,
|
||||||
|
port: dbConfig.db_port
|
||||||
|
});
|
||||||
|
|
||||||
|
// We just chain a PAUSE followed by a RESUME
|
||||||
|
client.connect();
|
||||||
|
client.query('PAUSE', (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
} else {
|
||||||
|
client.query('RESUME', (err, res) => {
|
||||||
|
client.end();
|
||||||
|
return callback(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user