Looks like you aren't awaiting the pool.end(). This could mean your test runner may exit before pool.end() resolves which could potentially be leaving open sockets.
pool.end()
afterAll(async () => { await pool.end(); });