-
Notifications
You must be signed in to change notification settings - Fork 112
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
As pointed out in this issue: #2168, the default behaviour when testing an app that uses BullMQ, is that it doesn't complete, due to the Redis connection still being open.
However, awaiting app.close() results in the test execution crashing and exiting with a non-zero exit code, indicating that the tests have failed, even though they succeeded.
Ran all test suites.
node:events:507
const err = new ERR_UNHANDLED_ERROR(stringifiedEr);
^
Error: Unhandled error. ([Error: Connection is closed.])
at RedisConnection.emit (node:events:507:17)
at /my-project/node_modules/bullmq/src/classes/redis-connection.ts:133:41
at processTicksAndRejections (node:internal/process/task_queues:105:5) {
code: 'ERR_UNHANDLED_ERROR',
context: [Error: Connection is closed.]
}
Node.js v22.17.0
I've tried every single suggested solution from here: https://stackoverflow.com/questions/62975121/close-redis-connection-when-using-nestjs-queues, and it always fails with the above error. (Some of them add additional errors, but this one seems to be the core of the problem.)
Minimum reproduction code
I'm unfortunately blocked from doing this on my work laptop.
Steps to reproduce
In a project that uses BullMQ:
- Call
await app.close()in theafterAll/afterEachhook. - Run
npm run test:e2e
Expected behavior
Well, I would expect it to work out of the box, without adding app.close(). It seems like it should automatically close the app when all references to it become out of scope. If not, I don't see why app.close() isn't part of the auto-generated code.
All of that aside, I'd obviously expect that the test execution would finish without throwing an error.
Package version
11.0.2
Bull version
5.56.1 (bullmq)
NestJS version
11.0.1
Node.js version
v22.17.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
I've only reproduced this in our project, but I'll hopefully have time to create the minimum reproduction code when I get home. The project in which it was reproduced, there are multiple queues and workers, so I suppose it is possible that it would work in a simpler project with only one queue and one worker. I'll get back to you when I've been able to produce the minimum reproduction code.