-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for mocking Redis when in development mode. #86
Comments
Real talk though, how do I do run unit tests without something like this. My CI pipelines dont allow external connections.
This apparently doesn't work. Queue will still attempt to connect to a external Redis instnace. |
Do you think something like |
no, it won't. |
The implementation would have to require a change to bullmq? Just trying to find a solution and have also seen this module, but I just don't have too much experience working with Redis |
None of the mocks available support lua scripts. The one that you propose for example: yeahoffline/redis-mock#121 |
@convenientstop I think it should work now thanks |
Interesting, I was still running into issues and thought I had updated to a version that has that change. Would you mind sharing your implementation or an example here? |
I'll probably have to drop BullMQ from our project, the thing is as much as you want it to work with tests, whenever some check fails with the connection you provide (mocked or otherwise), it uses it's own IORedis to connect to defaults. If I provide an IORedis connection and you don't like it somehow, or it doesn't work, please fail gracefully, throw an error or something instead of going rogue and silently try to succeed with your own means behind the user's control. |
I forgot and never actually tried to implement this. Maybe I was wrong and it does not work. |
Not sure if this helpful, but heres a mock we are using for bullmq 1.4.2. We aren't extensively unit testing things like attempts / exponential backoff, etc. so only using this mock for the barebones unit tests:
|
So we would just need to make sure bullmq assumes ioredis-mock is a valid redis instance,, I think. This currently works for me just fine: import * as bullUtils from 'bullmq/dist/utils';
jest.mock('ioredis', () => require('ioredis-mock/jest'));
const bullMock = jest.spyOn(bullUtils, 'isRedisInstance');
bullMock.mockImplementation((_obj: unknown) => {
return true;
}); If |
Highly unlikely they will implement lua scripting in ioredis-mock though... |
@manast according to https://github.com/stipsan/ioredis-mock/blob/HEAD/compat.md |
Guys I have nausea after trying to mock BullMQ, it is just working irrationally. I mean I have it working perfectly fine in another project and now I just copied and pasted the same code to another proj and it is not. I also checked their versions and they are exactly the same, here is the freaking error message which does not make sense to me:
|
@kasir-barati it simply seems that it is trying to connect to a Redis instance that is not running in your local machine. |
@manast Thanks for the quick reply. TBH I am cracked this nut and learned that this is all because of NestJS doing some magic behind the scene. But what makes me wonder if something is missing in the BullMQ or NestJS is the fact that I have a Redis instance up and running as I explained it here in dev.to. You can also see my repo here: https://github.com/kasir-barati/bugs/tree/bullmq-worker-needs-connection So long story short |
@kasir-barati that error is quite clear, there is no Redis instance running in localhost at port 6379. |
First thanks for the reply, second I have added a new test case just to prove that we have a Redis instance up and running: https://github.com/kasir-barati/bugs/blob/6a0a8a1129d42b935ba6e8c0f683830a066e2d0f/test/cart.e2e-spec.ts#L9-L30 I am not sure if you read it or not but in my original comment I also mentioned it, I have a Redis instance running. |
Ok, so you have a Redis instance running locally but BullMQ fails to connect to it, so what's your theory? my guess is as good as yours, but one thing I know, this is not a bug in BullMQ. |
Locking this conversation as it is off topic. |
When developing features locally, I am forced to either connect to my hosted redis cluster, or run redis locally. For my purposes this is unnecessary, and adds additional setup time. Would be nice to include a flag for just using a in memory queue for development and testing.
const devQueue = new Queue('devQueue', {useDevelopmentQueue: true})
This would implement the same interface as Redis, but allow for storing events in process memory.
The text was updated successfully, but these errors were encountered: