loopbackio / loopbackio/loopback-next

Jest detects open handles when disconnecting a MongoDB datasource

Aperta
#9,347 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

### Describe the bug

When closing a connection to a MongoDB database, Jest reports that there are still open handles.

Packages
```
"dependencies": {
"@loopback/repository": "^5.1.4",
"loopback-connector-mongodb": "^6.2.0"
},
"devDependencies": {
"jest": "^29.5.0"
}
```

Test example
```
const {juggler} = require("@loopback/repository");

describe('Should close without open handles', () => {

let datasource;

beforeAll(async () => {
datasource = new juggler.DataSource({
name: "mongo",
connector: "mongodb",
url: "",
host: "127.0.0.1",
port: 27017,
user: "",
password: "",
database: "customers",
useNewUrlParser: true,
authSource: "admin",
})

await datasource.connect();
});

afterAll(async () => {
await datasource.disconnect();
await datasource.stop();
});

it('Handles are still open', () => {
expect(true).toBe(true);
});
});
```

This does not happen with a memory data store (as I assume there is no actual connection).

### Expectation

The test completes without any errors/warnings

### Reality

Jest complains that there are still open handles
```
Jest has detected the following 1 open handle potentially keeping Jest from exiting:

● TCPWRAP

6 |
7 | beforeAll(async () => {
> 8 | datasource = new juggler.DataSource({
| ^
9 | name: "mongo",
10 | connector: "mongodb",
11 | url: "",

at makeConnection (node_modules/mongodb/lib/core/connection/connect.js:310:20)
at Array.reduce ()
at Object. (__tests__/example.test.js:8:22)
```

### Repository with minimal reproducible error

https://github.com/MattLishmanCtM/lb-connection-error

Node version: v18.12.0
OS: MacOS Ventura

Is there something I am missing about this?
Is there some other form of disconnecting/stopping that I should be doing?

I realise the officially supported package for LoopBack as a whole is Mocha but I need to use the repository package as a standalone with Jest.

### Logs

_No response_

### Additional information

_No response_

### Reproduction

https://github.com/MattLishmanCtM/lb-connection-error

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione minima e __tests__/example.test.js, quindi esamina il ciclo di vita di datasource.connect(), disconnect() e stop() utilizzato nel test. Riproduci l’esecuzione di Jest con il datasource MongoDB e verifica che il test termini senza l’avviso segnalato di TCPWRAP per un handle aperto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, mongodb, node.js
Ambito
backend, database, testing
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.