-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 detect open handles in tests after upgrading from 8.9.6 to 8.10.0 #15241
Comments
I had also run into this, a fix is in #15245. |
The only way I've been able to repro this is with creating a model but never connecting to MongoDB: const mongoose = require('mongoose');
// Define a User schema and model
const userSchema = new mongoose.Schema({
name: String,
email: String,
age: Number
});
const User = mongoose.model('User', userSchema);
describe('Database connection', () => {
it('test', function () {
});
}); Output:
Is there some other way that you've been able to repro this @hasezoey @Freezystem ? This just means there's some connection helpers that are buffered when tests are done, which likely means registering models or executing operations on a connection that was never opened. |
In my use-case for typegoose, the only issues happen when i try to set Jest detected output for those lines ● Timeout
101 | mongoose.model.bind(mongoose);
102 |
> 103 | const compiledModel: mongoose.Model<any> = modelFn(name, buildSchema(cl, mergedOptions));
| ^
104 |
105 | return addModelToTypegoose<U, QueryHelpers>(compiledModel, cl, {
106 | existingMongoose: mergedOptions?.existingMongoose,
at node_modules/mongoose/lib/connection.js:838:19
at NativeConnection._waitForConnect (node_modules/mongoose/lib/connection.js:837:7)
at _createCollection (node_modules/mongoose/lib/model.js:1106:16)
at Function.init (node_modules/mongoose/lib/model.js:1119:16)
at Mongoose._model (node_modules/mongoose/lib/mongoose.js:667:9)
at NativeConnection.model (node_modules/mongoose/lib/connection.js:1454:23)
at getModelForClass (src/typegoose.ts:103:46)
at Object.<anonymous> (test/tests/disableCache.test.ts:288:30) This was working (no errors / open handles) before #15229. For my use-case some alternatives could be:
For now the Also kinda related but not exactly the same problem, wouldnt having the timeout in the |
One alternative would be to just disable const mongoose = require('mongoose');
// Define a User schema and model
const userSchema = new mongoose.Schema({
name: String,
email: String,
age: Number
}, { autoIndex: false, autoCreate: false });
const User = mongoose.model('User', userSchema);
describe('Database connection', () => {
it('test', function () {
});
}); The idea of buffering on Potential workaround: make |
I think it would be good to have automatic things not have a timeout. |
fix: avoid connection buffering on init if autoCreate: false
… unintentional dangling open handles Fix #15241
fix(model): avoid adding timeout on `Model.init()` buffering to avoid unintentional dangling open handles
Yes that was exactly my case. It was in tests that were instanciating a mongoose instance but did not connect to the DB. |
Fix should be in 8.10.1, can you please upgrade and let me know if that fixed the issue @Freezystem ? |
It's fixed ! Thank you a lot 🙏🏼 |
Prerequisites
Mongoose version
8.10.0
Node.js version
20
MongoDB server version
6.0.20
Typescript version (if applicable)
No response
Description
Jest detects open handles after upgrading from
8.9.6
to8.10.0
.Here are some logs:
My code hasn't changed it was just a mongoose dependency upgrade. When I rollback the upgrade everything works fine again.
Steps to Reproduce
upgrade from
8.9.6
to8.10.0
. Run tests that use jest and mongoose connections.Expected Behavior
No response
The text was updated successfully, but these errors were encountered: