test-end-callback.js 520 B

12345678910111213141516171819202122232425262728
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. connection.connect();
  5. var gotEnd = false;
  6. connection.on('end', function(err) {
  7. assert.equal(gotEnd, false);
  8. assert.ok(!err);
  9. gotEnd = true;
  10. });
  11. var gotCallback = false;
  12. connection.end(function(err) {
  13. if (err) throw err;
  14. assert.equal(gotCallback, false);
  15. gotCallback = true;
  16. });
  17. process.on('exit', function() {
  18. assert.equal(gotCallback, true);
  19. assert.equal(gotEnd, true);
  20. });