From 71b8699f476d516a3dd27fa88c2ef30b7680a078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 5 Nov 2018 17:16:22 +0100 Subject: [PATCH] Shut down the pool after setting the database timeout --- test/support/test-client.js | 53 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/test/support/test-client.js b/test/support/test-client.js index f9c17cd1..8f9a8376 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -1262,41 +1262,38 @@ TestClient.prototype.getDBConnection = function () { return psql; }; +const pg = require('pg'); + TestClient.prototype.setUserDatabaseTimeoutLimit = function (timeoutLimit, callback) { const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db'; const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 }); const publicuser = global.environment.postgres.user; - - // we need to guarantee all new connections have the new settings - const pg = require('pg'); - - pg.once('end', () => { - - const psql = new PSQL({ - user: 'postgres', - dbname: dbname, - host: global.environment.postgres.host, - port: global.environment.postgres.port - }); - - step( - function configureTimeouts () { - const timeoutSQLs = [ - `ALTER ROLE "${publicuser}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}`, - `ALTER ROLE "${dbuser}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}`, - `ALTER DATABASE "${dbname}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}` - ]; - - const group = this.group(); - - timeoutSQLs.forEach(sql => psql.query(sql, group())); - }, - callback - ); + const psql = new PSQL({ + user: 'postgres', + dbname: dbname, + host: global.environment.postgres.host, + port: global.environment.postgres.port }); - pg.end(); + step( + function configureTimeouts () { + const timeoutSQLs = [ + `ALTER ROLE "${publicuser}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}`, + `ALTER ROLE "${dbuser}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}`, + `ALTER DATABASE "${dbname}" SET STATEMENT_TIMEOUT TO ${timeoutLimit}` + ]; + + const group = this.group(); + + timeoutSQLs.forEach(sql => psql.query(sql, group())); + }, + // we need to guarantee all new connections have the new settings + function refreshPoolConnection () { + pg.once('end', () => callback()); + pg.end(); + } + ); }; TestClient.prototype.getAnalysesCatalog = function (params, callback) {