Nodeunit test hangs for async db call ORMnomnom

I am trying to write unit test for async db calls. I'm using NodeJS with ORMnomnom package installed as orm db access and nodeunit for unit testing. But it hang for this simple test:

Here is code test\test1.js

modelsdb = require('../model/model_db')

exports['test db'] = function (test) {
  test.expect(1);
  console.log('test db');
  modelsdb.MyTable.objects.all( function (err, data) { 
    test.ok(true, "this assertion should pass"); 
    test.done();
    console.log('test must finish here!');
  });
}

exports.testSomething = function(test){
  console.log('testSomething');
  test.expect(1);
  test.ok(true, "this assertion should pass");
  test.done();
};

When I run this test all assertions passed, I see my messages in console: 'test db' 'test must finish here!' 'testSomething' (means that test.done() reached inside callback function) but test doesn't finish. I need to stop it manually, get: 'Process finished with exit code 1'. If I change to test.ok(false,""), so I get AssertionError but test doesn't finish either. If I remove 'test db' and left only testSomething function - test finished as expected, all assertion passed.

I also try testpilot package which is based on nodeunit. It gives

test1
   FAIL : test db
      an error occurred during test:
         Error: timed out waiting for test

Any suggestions? Thanks.

Add a tearDown method to your exports to close mongoose's connection pool. As long as it's still open the test won't exit.

You don't show how you're opening your mongoose connection, but something like this:

exports.tearDown = function (callback) {
    mongoose.disconnect();
    callback();
};

I'm having a similar issue with nodeunit and q/mongoose - There is a bug that has been opened for it. I've tried to do the terrible process.exit(0) after calling test.done(), but any logging that is pending may not be flushed, so it isn't ideal. Ended up having to call process.exit(0) in a timeout block.