diff --git a/lib/connection-pool.js b/lib/connection-pool.js old mode 100644 new mode 100755 index 0d553c3..13dfaf9 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -82,15 +82,12 @@ function createConnection(pooled) { self.log('connection closing because of error'); connection.removeListener('end', endHandler); - connection.close(); - pooled.status = RETRY; pooled.con = undefined; if (pooled.timeout) clearTimeout(pooled.timeout); pooled.timeout = setTimeout(createConnection.bind(self, pooled), self.retryDelay); - self.emit('error', err); }; diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 4b05942..b5adeef --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Connection Pool for tedious.", "main": "lib/connection-pool.js", "scripts": { - "test": "test" + "test": "mocha test/naming.test.js && mocha test/connection-pool.test.js" }, "repository": { "type": "git", @@ -37,7 +37,7 @@ ], "licenses": "MIT", "dependencies": { - "tedious": "^1.8.0" + "tedious": "^1.13.0" }, "devDependencies": { "mocha": ">=1.6.0" diff --git a/test/connection-pool.test.js b/test/connection-pool.test.js old mode 100644 new mode 100755 index f1f2a8d..a133340 --- a/test/connection-pool.test.js +++ b/test/connection-pool.test.js @@ -11,6 +11,7 @@ var connectionConfig = { database: 'test' } }; + /* create a db user with the correct permissions: CREATE DATABASE test CREATE LOGIN test WITH PASSWORD=N'test', DEFAULT_DATABASE=test, CHECK_POLICY=OFF @@ -259,14 +260,14 @@ describe('ConnectionPool', function () { }, 300); }); - it('lost connection handling', function (done) { + it('connection error handling', function (done) { this.timeout(10000); var poolConfig = {min: 1, max: 5}; + var pool = new ConnectionPool(poolConfig, connectionConfig); pool.on('error', function(err) { assert(err && err.name === 'ConnectionError'); - pool.drain(done); }); //This simulates a lost connections by creating a job that kills the current session and then deletesthe job. @@ -290,7 +291,8 @@ describe('ConnectionPool', function () { 'SELECT 42'; var request = new Request(command, function (err, rowCount) { - assert(false); + assert(err); + pool.drain(done); }); request.on('row', function (columns) { @@ -342,7 +344,7 @@ describe('ConnectionPool', function () { this.timeout(10000); var poolConfig = {min: 3}; - var pool = new ConnectionPool(poolConfig, {}); + var pool = new ConnectionPool(poolConfig, connectionConfig); pool.acquire(function() { });