Node.js: Jest + redis.quit() but open handle warning persists
Figured it out after posting. I forgot to post the answer here.
It has to do with how redis.quit()
handles its callback.
It creates a new thread so we need to wait for the entire eventloop stack to cycle again. See below for the workaround.
async function shutdown() {
await new Promise((resolve) => {
redis.quit(() => {
resolve();
});
});
// redis.quit() creates a thread to close the connection.
// We wait until all threads have been run once to ensure the connection closes.
await new Promise(resolve => setImmediate(resolve));
}