dwyl / hapi-postgres-connection

:zap: Creates a PostgreSQL Connection (Pool) available anywhere in your Hapi App
GNU General Public License v2.0
40 stars 13 forks source link

Tests take ages to actually close #21

Closed jay-meister closed 1 year ago

jay-meister commented 7 years ago

I have a teardown test:

var tape = require('tape');
var server = require('../example/server.js');

tape('check that plugin is being attached to the request object', function (t) {
  server.inject({
    method: 'GET',
    url: '/'
  }, function (result) {
    t.equal(result.statusCode, 200,
      'Looks for the endpoint where method is attached to request object.');
    t.end();
  });
});

tape('teardown', function (t) {
  server.stop();
  t.end();
});

The test hangs for about 1 - 2 minutes before actually closing the connection and giving me the results of the test.

I have registered another server.on('stop', () => console.log('stopping')); event listener which gets called immediately and I have logged in the module itself, the event emitter and listener are working fine and PG_CON has length 2.

nelsonic commented 7 years ago

How long are we talking? (seconds or minutes...?) 🤔

jay-meister commented 7 years ago

The test hangs for about 1 - 2 minutes before actually closing the connection and giving me the results of the test.

From what I can tell, it does close the connections instantly, but the tests still seem hang for about 2 minutes.

jay-meister commented 7 years ago

@SimonLab was wondering if it was something to do with the default idleTimeoutMillis property in the config.

var config = {
  user: 'foo', //env var: PGUSER
  database: 'my_db', //env var: PGDATABASE
  password: 'secret', //env var: PGPASSWORD
  host: 'localhost', // Server hosting the postgres database
  port: 5432, //env var: PGPORT
  max: 10, // max number of clients in the pool
  idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
};