-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add maxUses pool config option #2147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const expect = require('expect.js') | ||
const co = require('co') | ||
const _ = require('lodash') | ||
|
||
const describe = require('mocha').describe | ||
const it = require('mocha').it | ||
|
||
const Pool = require('../') | ||
|
||
describe('maxUses of 2', () => { | ||
it('can create a single client and use it once', co.wrap(function * () { | ||
const pool = new Pool({ maxUses: 2 }) | ||
expect(pool.waitingCount).to.equal(0) | ||
const client = yield pool.connect() | ||
const res = yield client.query('SELECT $1::text as name', ['hi']) | ||
expect(res.rows[0].name).to.equal('hi') | ||
client.release() | ||
pool.end() | ||
})) | ||
|
||
it('getting a connection a second time returns the same connection and releasing it also closes it', co.wrap(function * () { | ||
const pool = new Pool({ maxUses: 2 }) | ||
expect(pool.waitingCount).to.equal(0) | ||
const client = yield pool.connect() | ||
client.release() | ||
const client2 = yield pool.connect() | ||
expect(client).to.equal(client2) | ||
expect(client2._ending).to.equal(false) | ||
client2.release() | ||
expect(client2._ending).to.equal(true) | ||
return yield pool.end() | ||
})) | ||
|
||
it('getting a connection a third time returns a new connection', co.wrap(function * () { | ||
const pool = new Pool({ maxUses: 2 }) | ||
expect(pool.waitingCount).to.equal(0) | ||
const client = yield pool.connect() | ||
client.release() | ||
const client2 = yield pool.connect() | ||
expect(client).to.equal(client2) | ||
client2.release() | ||
const client3 = yield pool.connect() | ||
expect(client3).not.to.equal(client2) | ||
client3.release() | ||
return yield pool.end() | ||
})) | ||
|
||
it('logs when removing an expended client', co.wrap(function * () { | ||
const messages = [] | ||
const log = function (msg) { | ||
messages.push(msg) | ||
} | ||
const pool = new Pool({ maxUses: 1, log }) | ||
const client = yield pool.connect() | ||
client.release() | ||
expect(messages).to.contain('removing expended client') | ||
return yield pool.end() | ||
})) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer: It took me a while to figure out why this test kept failing with an error about the value being undefined, so I added the new argument so we can differentiate an unexpected error scenario and subsequently report it as a test failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice - thanks. As an aside, I think it's probably time I deprecate BYOP for [email protected] as all current supported versions of node include a native promise.