test-server-unexpected-disconnect.js 816 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var common = require('../../common');
  2. var connection = common.createConnection({port: common.fakeServerPort});
  3. var assert = require('assert');
  4. var endErr;
  5. connection.on('end', function(err) {
  6. assert.ok(!endErr);
  7. endErr = err;
  8. });
  9. var queryErr;
  10. var server = common.createFakeServer();
  11. server.listen(common.fakeServerPort, function(err) {
  12. if (err) throw err;
  13. connection.query('SELECT 1', function(err) {
  14. assert.ok(!queryErr);
  15. queryErr = err;
  16. });
  17. });
  18. server.on('connection', function(connection) {
  19. connection.handshake();
  20. connection.on('query', function(packet) {
  21. server.destroy();
  22. });
  23. });
  24. process.on('exit', function() {
  25. assert.strictEqual(queryErr.code, 'PROTOCOL_CONNECTION_LOST');
  26. assert.strictEqual(queryErr.fatal, true);
  27. assert.strictEqual(endErr, queryErr);
  28. });