Permalink
Browse files

Always call the ConnectionPool.shutdown()-callback.

- If shutting down, the callback is being passed an error.
  • Loading branch information...
ctavan committed Jan 30, 2012
1 parent 29776b6 commit 54987ca7733d31bf8c39708124cb04ece7120a95
Showing with 38 additions and 3 deletions.
  1. +4 −3 lib/driver.js
  2. +34 −0 test/test_driver.js
View
@@ -742,14 +742,15 @@ PooledConnection.prototype._getNextCon = function(callback) {
PooledConnection.prototype.shutdown = function(callback) {
var self = this;
callback = callback || function() {};
// Start shutdown mode, causes no new execute()'s to be accepted
if (self.shuttingDown) {
return;
var err = new Error('Already shutting down.');
return callback(err);
}
self.shuttingDown = true;
callback = callback || function() {};
// Close all open connections as soon as the pool has drained
self.once('drain', function() {
self._closeConnections(function() {
View
@@ -1083,3 +1083,37 @@ exports.testPooledConnectionShutdown = function(test, assert) {
test.finish();
});
};
exports.testPooledConnectionShutdownTwice = function(test, assert) {
var hosts = ['127.0.0.1:19170'];
var conn = new PooledConnection({'hosts': hosts, 'keyspace': 'Keyspace1'});
var expected = 100;
var cbcount = 0;
var spy = function(err, res) {
assert.ifError(err);
cbcount++;
};
for (var i = 0; i < expected; i++) {
(function(index) {
conn.execute('UPDATE CfUtf8 SET ? = ? WHERE KEY = ?', ['col', 'val', 'key'+index], spy);
})(i);
}
assert.ok(!conn.shuttingDown);
conn.shutdown(function(err) {
assert.ifError(err);
assert.equal(cbcount, expected);
assert.ok(secondCbCalledImmediatelyWithError);
test.finish();
});
// Make sure second callback gets called immediately with an error
var secondCbCalledImmediatelyWithError = false;
assert.ok(conn.shuttingDown);
conn.shutdown(function(err) {
assert.ok(err);
secondCbCalledImmediatelyWithError = true;
});
};

0 comments on commit 54987ca

Please sign in to comment.