Skip to content
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

Jest Detects Open Handles when using a Queue #1464

Closed
pshaddel opened this issue Oct 6, 2022 · 3 comments
Closed

Jest Detects Open Handles when using a Queue #1464

pshaddel opened this issue Oct 6, 2022 · 3 comments

Comments

@pshaddel
Copy link

pshaddel commented Oct 6, 2022

BullMQ Version: ^2.1.3

Problem
If we let BullMQ creates the connection to Redis we get some errors from jest and it detect open handles that are pointed to the open Redis connection.

export const paintQueue = new Queue("Paint", {
      connection: {
         port: 6379,
         host: "127.0.0.1"
      }
    })

A test that I use and get error of open handles:

it('should get job after creating the job', async () => {
  const job = await paintQueue.add('jobName', 'data', {
    removeOnComplete: false,
    removeOnFail: false
  })
  expect(job).toBeTruthy()
})

The workaround that I use for now is to create the connection outside the queue and expose it:

export const paintQueueConnection = new Redis({
  host: config.redis.host,
  port: config.redis.port
})
export const paintQueue = new Queue("Paint", {
      connection: paintQueueConnection
    })

Now I can solve this error by adding this:

afterAll(()=> {
paintQueueConnection.disconnect()
})

The problem is that the only exposed function is add and there is no way you can close the redis connection.

For the Worker case when you call disconnect it gracefully ends the redis connection and you see no errors.

Suggestion:
Exposing a disconnect function similar to Worker for closing a Queue

Any help or suggestion is appreciated, Or if someone has any idea I would be happy to help to solve it.

@manast
Copy link
Contributor

manast commented Oct 6, 2022

You need to use "close()" to close your Queues: https://api.docs.bullmq.io/classes/Queue.html#close

@manast manast closed this as completed Oct 6, 2022
@pshaddel
Copy link
Author

pshaddel commented Oct 6, 2022

You need to use "close()" to close your Queues: https://api.docs.bullmq.io/classes/Queue.html#close

Thanks a lot. The problem was probably ts definitions. Now I am calling close function and I have to ignore the typescript compiler because of this error:

Property 'close' does not exist on type 'Queue<any, any, string> | { add: (...args: any[]) => Promise<string>; }'.
  Property 'close' does not exist on type '{ add: (...args: any[]) => Promise<string>; }'

@manast
Copy link
Contributor

manast commented Oct 6, 2022

The definitions are fine, something else is wrong in your particular setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants