Skip to content

Commit 5055b3a

Browse files
authored
Merge pull request brianc#58 from brianc/bmc/add-test-and-deprecate-method
Add additional pool test & deprecate .end
2 parents d0e67a9 + cedce4b commit 5055b3a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ Cursor.prototype._getRows = function(rows, cb) {
163163
this.connection.flush()
164164
}
165165

166-
Cursor.prototype.end = function(cb) {
166+
// users really shouldn't be calling 'end' here and terminating a connection to postgres
167+
// via the low level connection.end api
168+
Cursor.prototype.end = util.deprecate(function(cb) {
167169
if (this.state !== 'initialized') {
168170
this.connection.sync()
169171
}
170172
this.connection.once('end', cb)
171173
this.connection.end()
172-
}
174+
}, 'Cursor.end is deprecated. Call end on the client itself to end a connection to the database.')
173175

174176
Cursor.prototype.close = function(cb) {
175177
if (this.state === 'done') {

test/pool.js

+21
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,25 @@ describe('pool', function() {
8383
done()
8484
})
8585
})
86+
87+
it('can close multiple times on a pool', async function() {
88+
const pool = new pg.Pool({ max: 1 })
89+
const run = async () => {
90+
const cursor = new Cursor(text)
91+
const client = await pool.connect()
92+
client.query(cursor)
93+
new Promise(resolve => {
94+
cursor.read(25, function(err) {
95+
assert.ifError(err)
96+
cursor.close(function(err) {
97+
assert.ifError(err)
98+
client.release()
99+
resolve()
100+
})
101+
})
102+
})
103+
}
104+
await Promise.all([run(), run(), run()])
105+
await pool.end()
106+
})
86107
})

test/transactions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('transactions', () => {
2828
await client.end()
2929
})
3030

31-
it.only('can execute multiple statements in a transaction if no data', async () => {
31+
it('can execute multiple statements in a transaction if no data', async () => {
3232
const client = new pg.Client()
3333
await client.connect()
3434
await client.query('begin')

0 commit comments

Comments
 (0)