loopbackio / loopbackio/loopback-next
Jest detects open handles when disconnecting a MongoDB datasource
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
### 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
最小限の再現例と __tests__/example.test.js から始め、その後、テストで使用されている datasource.connect()、disconnect()、stop() のライフサイクルを調べます。MongoDB datasource で Jest の実行を再現し、報告されている TCPWRAP の open-handle 警告なしにテストが終了することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, mongodb, node.js
- 領域
- backend, database, testing
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100