-
Notifications
You must be signed in to change notification settings - Fork 2k
0.4.0 'gulp test' hangs because mongoose connections are staying open #450
Comments
Does the referenced commit and changes made in |
Your commit only references the gulpfile. As a modification to your commit, I think you want to pass a callback into the disconnect method on the mongoose connection so you can call the gulp done method when the disconnect is complete. Eg: mongoose.disconnect(function(err) { Then, you can have the config/lib/mongoose.js file do something like this: module.exports.disconnect = function(cb) { But otherwise, yes this is the same thing I did to fix the issue. |
Fixed gulp tracking in the latest commit. Mongoose lib disconnect method was already there before. |
You can't do this: mongoose.connect(done); because gulp interprets any parameter to the callback as an error. So, in this case, the build immedaitely fails on the openMongoose task when the mongoose.connect callback function passes the db as a parameter. So, you need to do this instead on the openMongoose task: mongoose.connect(function(db) { |
The build passes. |
It isn't running the gulp build. |
Out of curiosity, what error does Gulp throw because of that? |
Gulp fails because the task is reporting an error: [22:53:28] 'openMongoose' errored after 247 ms The '[object Object]' being referenced in the error is the db object returned by the mongoose connect function. Gulp's docs specify that calling the callback function with any parameter is interpreted as an error.
Since you are effectively telling gulp that task has failed, it doesn't even both to run the tests. Since the Mongoose db connection is still open at that point, it still hangs. You can check out the branch and do "gulp test" to reproduce. |
Fixed in the latest commit. |
Fixed. |
Just discovered that this issue isn't entirely fixed. The remaining issue is that when the tests fail, the 'closeMongoose' task isn't called, so the build still hangs. One solution is to suppress errors on both the mocha and karma build tasks... eg: // Mocha tests task
gulp.task('mocha', function () {
return gulp.src(testAssets.tests.server)
.pipe(plugins.mocha({
reporter: 'spec'
}))
.on('error', function (err) {
// Make sure failed tests don't cause gulp to exit, otherwise Mongoose won't cleanup
this.emit('end');
});
});
// Karma test runner task
gulp.task('karma', function (done) {
return gulp.src([])
.pipe(plugins.karma({
configFile: 'karma.conf.js',
action: 'run',
singleRun: true
}))
.on('error', function (err) {
// Make sure failed tests cause gulp to exit non-zero
this.emit('end');
});
}); If you do that, then the gulp tasks will run to completion and the 'closeMongoose' task will run. But, the issue with this approach is I don't think a CI server will know that the tests failed when they do. Other possible solutions include making the tests themselves create and close the mongoose connections in the pre/post hooks. Or, to add some code that manually invokes the closeMongoose task in the event of an error and then fails out of the build. |
I think a big issue is using runSequence because that doesn't seem to handle error propagation properly. Can you please format your code with syntax highlighting and proper indentation using markdown? |
Submitted a pull request for fixing this: #453 I changed the gulpfile so the mocha task calls mongoose.disconnect regardless of if the mocha tests pass or fail and passes the error back to the done callback if it exists. I should note, I've tested with both passing and failing mocha tests and karma tests. |
…ining what's going on in the mocha task.
Fix hanging gulp because mongoose connections are left open. Fixes #450.
Just merged #453 in, so this should be fixed. |
* commit 'a0495eabbd773ea642468ad77cfd28de0cfe3dab': Bump glob to version 5.0 Correctly encode and decode password salt meanjs#450 minor formatting fixes. meanjs#450 Fixing unrelated jshint warnings removed unused gulp-watch dependency meanjs#450 Use the error reported by mocha. Added some comments explaining what's going on in the mocha task. meanjs#450 Now the mocha task synchronously calls mongoose connect and disconnect. Fix Gulp throwing errors Cleanly track mongoose connection in test task sequence Properly track DB disconnect Gulp now closes the mongoose connection Disconnect method to close DB connection update gulp-sass to ensure node-0.12 compatibility Conflicts: config/config.js gulpfile.js package.json
The mongoose connection opened as part of the 'test' task in the gulp build is never closed. This causes gulp to hang at the completion of the tests.
The text was updated successfully, but these errors were encountered: