Revision: 54987ca7733d
Author: Christoph Tavan <d...@tavan.de>
Date: Mon Jan 30 13:54:09 2012
Log: Always call the ConnectionPool.shutdown()-callback.
- If shutting down, the callback is being passed an error.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=54987ca7733d
Modified:
/lib/driver.js
/test/test_driver.js
=======================================
--- /lib/driver.js Mon Jan 30 14:58:56 2012
+++ /lib/driver.js Mon Jan 30 13:54:09 2012
@@ -742,14 +742,15 @@
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() {
=======================================
--- /test/test_driver.js Mon Jan 30 14:58:56 2012
+++ /test/test_driver.js Mon Jan 30 13:54:09 2012
@@ -1083,3 +1083,37 @@
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;
+ });
+};