diff --git a/lib/Pool.js b/lib/Pool.js index 29b9e744d..6378e0911 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -28,14 +28,27 @@ Pool.prototype.getConnection = function (cb) { } var connection; - var pool = this; if (this._freeConnections.length > 0) { connection = this._freeConnections.shift(); - return this.acquireConnection(connection, cb); } + return this.createConnection(cb); + +}; + +Pool.prototype.createConnection = function (cb) { + + if (this._closed) { + return process.nextTick(function(){ + return cb(new Error('Pool is closed.')); + }); + } + + var connection; + var pool = this; + if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) { connection = new PoolConnection(this, { config: this.config.newConnectionConfig() }); diff --git a/test/unit/pool/test-connection-create.js b/test/unit/pool/test-connection-create.js new file mode 100644 index 000000000..09f8d82ee --- /dev/null +++ b/test/unit/pool/test-connection-create.js @@ -0,0 +1,25 @@ +var assert = require('assert'); +var common = require('../../common'); +var Connection = common.Connection; +var EventEmitter = require('events').EventEmitter; +var pool = common.createPool({ + port: common.fakeServerPort +}); +var PoolConnection = common.PoolConnection; + +var server = common.createFakeServer(); + +server.listen(common.fakeServerPort, function(err) { + assert.ifError(err); + + pool.createConnection(function(err, connection) { + assert.ifError(err); + + assert(connection instanceof PoolConnection); + assert(connection instanceof Connection); + assert(connection instanceof EventEmitter); + + connection.destroy(); + server.destroy(); + }); +});