loopbackio / loopbackio/loopback-next
Jest detects open handles when disconnecting a MongoDB datasource
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
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 (<anonymous>)
at Object.<anonymous> (__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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der minimalen Reproduktion und tests/example.test.js und untersuchen Sie anschließend den in diesem Test verwendeten Lifecycle von datasource.connect(), disconnect() und stop(). Führen Sie den Jest-Lauf mit der MongoDB-Datenquelle erneut aus und überprüfen Sie, dass der Test ohne die gemeldete TCPWRAP-Warnung zu offenen Handles beendet wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, mongodb, node.js
- Bereich
- backend, database, testing
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100