Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,15 @@ Pool.prototype.end = function (cb) {
}.bind(this))
}.bind(this))
}

Pool.prototype.size = function () {
return this.pool.getPoolSize()
}

Pool.prototype.available = function () {
return this.pool.availableObjectsCount()
}

Pool.prototype.borrowed = function () {
return this.pool.inUseObjectsCount()
}
22 changes: 16 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ describe('pool', function () {
it('removes client if it errors in background', function (done) {
var pool = new Pool()
pool.connect(function (err, client, release) {
expect(pool.size()).to.be(1)
expect(pool.available()).to.be(0)
expect(pool.borrowed()).to.be(1)
release()
if (err) return done(err)
client.testString = 'foo'
Expand All @@ -84,6 +87,9 @@ describe('pool', function () {
}, 10)
})
pool.on('error', function (err) {
expect(pool.size()).to.be(0)
expect(pool.available()).to.be(0)
expect(pool.borrowed()).to.be(0)
expect(err.message).to.be('on purpose')
expect(err.client).to.not.be(undefined)
expect(err.client.testString).to.be('foo')
Expand Down Expand Up @@ -135,12 +141,15 @@ describe('pool', function () {
it('connects and disconnects', function () {
var pool = new Pool()
return pool.connect().then(function (client) {
expect(pool.pool.availableObjectsCount()).to.be(0)
expect(pool.size()).to.be(1)
expect(pool.available()).to.be(0)
expect(pool.borrowed()).to.be(1)
return client.query('select $1::text as name', ['hi']).then(function (res) {
expect(res.rows).to.eql([{ name: 'hi' }])
client.release()
expect(pool.pool.getPoolSize()).to.be(1)
expect(pool.pool.availableObjectsCount()).to.be(1)
expect(pool.size()).to.be(1)
expect(pool.available()).to.be(1)
expect(pool.borrowed()).to.be(0)
return pool.end()
})
})
Expand All @@ -157,7 +166,7 @@ describe('pool', function () {
})
}).then(function (res) {
expect(res).to.have.length(30)
expect(pool.pool.getPoolSize()).to.be(9)
expect(pool.size()).to.be(9)
return pool.end()
})
})
Expand All @@ -168,8 +177,9 @@ describe('pool', function () {
return pool.query('SELECT $1::text as name', ['hi'])
}).then(function (queries) {
expect(queries).to.have.length(30)
expect(pool.pool.getPoolSize()).to.be(9)
expect(pool.pool.availableObjectsCount()).to.be(9)
expect(pool.size()).to.be(9)
expect(pool.available()).to.be(9)
expect(pool.borrowed()).to.be(0)
return pool.end()
})
})
Expand Down