Skip to content
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

Exit process when tests are complete #162

Closed
wants to merge 2 commits into from
Closed

Conversation

schloerke
Copy link

This helps when some test code has a hanging processes.

There are no more test cases to be covered, so exit.

Best,
Barret

@wraithan
Copy link

wraithan commented Apr 8, 2012

I'd also like this as I am starting nodeunit as part of a script that bootstraps then env then destroys it when done (doing integration tests) and the fact that it just hangs at the end is getting in my way.

@rdner
Copy link

rdner commented May 7, 2012

I use Travis CI and it doesn't work with nodeunit because nodeunit doesn't exit when all test done. I like nodeunit, it's very easy to use but I want to use it with CI.

@feugy
Copy link

feugy commented May 13, 2012

+1
I'm running it on windows (I know, I know...) And when the tests all succeeded, the program does not exit.

@alexzhuustc
Copy link

You program may still have pending procedure. For example, setTimeout(callback, 5000) will block the testing program against quit.

This change shouldn't be merged, or at least merged but not enabled by default.

@digitalrinaldo
Copy link

This really seems like it is an application issue. In my case I have to create a http server and listen for one request and then shut it down. I have the sumptom of nodeunit still running. If I can figure out how to shutdown the server then nodeunit would return. Shouldn't every node instance be able to be shutdown gracefully.

@rdner
Copy link

rdner commented Jun 18, 2012

I solve this issue by using a custom reporter which is the modified copy of default.js in lib/reporters folder. Just found a line:

 if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);

And added after:

if (!assertions.failures()) {
    process.exit(0);
}

It's work fine for me, tests shutdown the process on success.

@diversario
Copy link

Automatic process exit would be nice, that's for sure.

@kalifg
Copy link

kalifg commented Sep 14, 2012

+1 from me as well. This is very helpful for being able to wrap tests around some badly-written async code that we have.

@mlaccetti
Copy link

+1 - test.done() is called, but nothing happens; might be related to using q/mongoose?

@diversario
Copy link

It also happens with just mongodb-native, so could because some connections to db are still open?.. Not sure, I tried closing connections manually and that didn't fix it.

Doesn't matter, though, I've moved to Mocha. Nodeunit's last commit was 9 month ago, I consider this project dead.
I have mixed test suites now, but it's OK.

@mreinstein
Copy link
Collaborator

@diversario @schloerke I'm a new project maintainer, helping Caolan with getting some new changes pushed out. Definitely interested in working with you guys to get some fixes in place.

Echoing the sentiments of @alexzhuustc and @digitalrinaldo I'm inclined to think that this particular merge probably shouldn't be pulled. It's not really possible to deterministically figure out if something is hanging or taking a really long time to run. It's related to the classic comp sci 'halting problem" http://en.wikipedia.org/wiki/Halting_problem

If nodeunit isn't exiting at the end of your tests, there's probably a missing callback, or a database connection or some other stream is still open. I recommend binary searching through your tests. (Disable half of the tests, run nodeunit again. If nodeunit now exits cleanly, the code executed by the tests you disabled has the problem. If not, it's in the tests that are still enabled. Keep halving the included tests until you're able to narrow down the source of the problem.

I'm closing this issue, but I don't want to seem heavy-handed. If you are still having problems or others want to weigh in, we can re-open and discuss.

@mreinstein mreinstein closed this Mar 30, 2013
@nev-dru
Copy link

nev-dru commented Jan 2, 2015

I have the same issue where nodeunit hangs. I am connecting to a sql database and I tried both sync and async js functions. Both methods caused nodeunit to hang at after all tests completed. After a while of debugging I found that my idleTimeoutMillis poolConfig setting caused/fixed the hang time. My setting was 60000 (1 min) but if I change 60000->1 my query finishes and nodeunit does not hang (for more than a millisecond). It seems like most people had issues with mongodb calls but perhaps there is a similar setting somewhere.

------------------------------------------------------------------------------------
* --- other modules used --- *
Fiber = require('fibers');
Tedious = require('tedious');
ConnectionPool = require('tedious-connection-pool');
Request = Tedious.Request;
------------------------------------------------------------------------------------
* --- dbConfig.js --- *
...
db.poolConfig = {
  ...
  idleTimeoutMillis: 60000 // nodeunit hangs for 1 min.
  ...
};
db.pool = new ConnectionPool(db.poolConfig, db.dbConfig);
module.exports = db;
------------------------------------------------------------------------------------
* --- dbMethods.js --- *
function getConnection() {   
   var fiber = Fiber.current;
   var conn;
   db.pool.requestConnection(function(err, connection) {
      ...
      conn = connection;
      fiber.run();
   });
   Fiber.yield();
   return conn;  
}
function getData(sql) {
   var sqlConn = getConnection();
   var result = [];
   var fiber = Fiber.current;
   var req = new Request(sql, function(err) {
      ...
      fiber.run()     
   }).on('row', function(columns) {
      ...
      return result.push(row);
   });
   sqlConn.execSql(req);
   Fiber.yield();
   
   // here the connection is closed 
   // so I don't think nodeunit is waiting for an open db connection to close
   sqlConn.close();
    
   return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet