Skip to content

Commit

Permalink
Merge pull request #58 from brianc/bmc/add-test-and-deprecate-method
Browse files Browse the repository at this point in the history
Add additional pool test & deprecate .end
  • Loading branch information
brianc committed Oct 30, 2019
2 parents d0e67a9 + cedce4b commit 5055b3a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -163,13 +163,15 @@ Cursor.prototype._getRows = function(rows, cb) {
this.connection.flush()
}

Cursor.prototype.end = function(cb) {
// users really shouldn't be calling 'end' here and terminating a connection to postgres
// via the low level connection.end api
Cursor.prototype.end = util.deprecate(function(cb) {
if (this.state !== 'initialized') {
this.connection.sync()
}
this.connection.once('end', cb)
this.connection.end()
}
}, 'Cursor.end is deprecated. Call end on the client itself to end a connection to the database.')

Cursor.prototype.close = function(cb) {
if (this.state === 'done') {
Expand Down
21 changes: 21 additions & 0 deletions test/pool.js
Expand Up @@ -83,4 +83,25 @@ describe('pool', function() {
done()
})
})

it('can close multiple times on a pool', async function() {
const pool = new pg.Pool({ max: 1 })
const run = async () => {
const cursor = new Cursor(text)
const client = await pool.connect()
client.query(cursor)
new Promise(resolve => {
cursor.read(25, function(err) {
assert.ifError(err)
cursor.close(function(err) {
assert.ifError(err)
client.release()
resolve()
})
})
})
}
await Promise.all([run(), run(), run()])
await pool.end()
})
})
2 changes: 1 addition & 1 deletion test/transactions.js
Expand Up @@ -28,7 +28,7 @@ describe('transactions', () => {
await client.end()
})

it.only('can execute multiple statements in a transaction if no data', async () => {
it('can execute multiple statements in a transaction if no data', async () => {
const client = new pg.Client()
await client.connect()
await client.query('begin')
Expand Down

0 comments on commit 5055b3a

Please sign in to comment.