Skip to content

Commit

Permalink
test for #52
Browse files Browse the repository at this point in the history
  • Loading branch information
sidorares committed Nov 18, 2011
1 parent 9d4cce0 commit 9b463c9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/connectionerrors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var assert = require('assert');
var createConnection = require('./common').createConnection;
var net = require('net');

module.exports = {
'test connection closed during query': function(cb) {
var forwardport = 3500;

var s = net.createServer(function(cli) {
var my = net.createConnection(3306);
cli.pipe(my);
my.pipe(cli);

setTimeout(function() {
my.end();
cli.end();
}, 1000); // close port forwarding in 1 second
}).listen(forwardport);

var db = createConnection({port: forwardport});
db.query('select sleep(3)') // take approx 3 seconds to execute
.on('error', function(e) {
console.log('command 1 error handler');
console.log(e);
cb();
}).on('end', function() {
console.log('command 1 finished');
});

// start new command after connection is closed
setTimeout(function() {
console.log('sending second query');
db.query('select 1')
.on('error', function(e) {
console.log('command 2 error handler');
console.log(e);
cb();
}).on('end', function() {
console.log('command 2 finished');
});

}, 1500);
}
}

0 comments on commit 9b463c9

Please sign in to comment.