Skip to content

Commit

Permalink
Merge pull request tediousjs#25 from pekim/pr/24
Browse files Browse the repository at this point in the history
Pr/24 - Don't close connection on socket error + fix tests to newer driver behavior
  • Loading branch information
ben-page committed Oct 27, 2015
2 parents d5982d4 + 5d0ad40 commit 0588c9c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lib/connection-pool.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -37,7 +37,7 @@
],
"licenses": "MIT",
"dependencies": {
"tedious": "^1.8.0"
"tedious": "^1.13.0"
},
"devDependencies": {
"mocha": ">=1.6.0"
Expand Down
10 changes: 6 additions & 4 deletions test/connection-pool.test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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() { });

Expand Down

0 comments on commit 0588c9c

Please sign in to comment.