node-mongolian
node-mongolian copied to clipboard
temporary fix for issue 33
this fix will become obsolete when the node-mongodb dependency gets removed, but here's a fix that worked for me in case others need it now.
Is there some way we can build a test case for this? I'm not entirely convinced that the problem goes away with the new code branch.
The problem is a collection of the following:
- 'server = new Server()' will call scanServer, which sends a command to 'admin'.
- my code happened to want to quit immediately after creating a Server (in the same event loop), because there were no indices to ensure.
- calling 'server.close()' immediately upon Server creation hangs because the 'admin' command from (1) didn't respond yet, which means taxman didn't have a chance to set .value.
Testing is not easy, the failure effect is that typical node scripts will hang (I guess because the server connection is open), whereas nodeunit may be forcing an exit() once all the test.done() have been called.
You can easily test hanging on the console with the following script.
var Mongolian = require('./mongolian')
var db = new Mongolian('mongo://localhost/mongolian_test', { log:false })
var hang = true
if (hang) {
db.dropdatabase(function(error) {
})
db.server.close()
} else {
db.dropdatabase(function(error) {
db.server.close()
})
}