Solvedobjection.js Need to explicit destroy knex in order to stop the script

Hi, I initialize Model this way:

const Knex = require('knex');
const Model = require('objection').Model;
const knex = new Knex({
  client: 'pg',
  pool: { min: 1, max: 10 },
  connection: {},
  searchPath: 'knex,public',
});
Model.knex(knex);

The problem I have is when I run tests with mocha, mocha never ends until I run:

knex.destroy();

And even if I run it, mocha keep waiting for extra 5-10 seconds, and after actually ends.
Which makes me believe, that Objection or knex still have some process running to keep pool connections alive.

Any suggestions how could I cut this "waiting" time in mocha?

18 Answers

✔️Accepted Answer

add idleTimeoutMillis: 500 too if you want to use knex in jest

Other Answers:

Hi!

I use after(() => knex.destroy()) and that's enough to let the process die immediately. Neither objection nor knex start any processes.

Have you tried setting the minimum pool size to zero?