Mocha timeout errors for Sequelize

This post goes over how to fix Mocha timeout errors for Sequelize integration tests.


My Sequelize integration tests were failing with the error:

1) "after all" hook in "{root}"

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.


I found that this was related to the connection pool (it was too low in my Sequelize config).

I checked the maximum database connection pool size:

SHOW max_connections;

The PostgreSQL database I was using has a maximum connection pool of 100.

Since my integration tests run on 3 processes, I set the max pool size to 30 so the total number (90) is below the max connection pool limit (100).

After updating the Sequelize options:

const { Sequelize } = require('sequelize');

const sequelize = new Sequelize(/* ... */, {
  // ...
  pool: {
    max: 30,

I reran the tests:

npx mocha

While monitoring the realtime activity:

FROM pg_stat_activity;

And my integration tests passed without a timeout error. Success!

Please support this site and join our Discord!