Skip to content

Commit

Permalink
Update code to use handle error event
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed Aug 12, 2024
1 parent 4ed2bcc commit 54dc7af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ class Client extends EventEmitter {

_handleParseComplete() {
if (this.activeQuery == null) {
this.emit('error', new Error('Received parseComplete when not in parsing state'))
const error =new Error('Received parseComplete when not in parsing state')

Check failure on line 386 in packages/pg/lib/client.js

View workflow job for this annotation

GitHub Actions / lint

Replace `new·Error('Received·parseComplete·when·not·in·parsing·state')·` with `·new·Error('Received·parseComplete·when·not·in·parsing·state')`

Check failure on line 386 in packages/pg/lib/client.js

View workflow job for this annotation

GitHub Actions / lint

Replace `new·Error('Received·parseComplete·when·not·in·parsing·state')·` with `·new·Error('Received·parseComplete·when·not·in·parsing·state')`
this._handleErrorEvent(error)
return
}
// if a prepared statement has a name and properly parses
Expand Down
17 changes: 11 additions & 6 deletions packages/pg/test/integration/gh-issues/3174-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ suite.testAsync('Out of order parseComplete on simple query is catchable', async
errorHit = true
})

await client.query('SELECT NOW')
await client.query('SELECT NOW()')
await delay(50)
await client.query('SELECT NOW')
await delay(50)
await client.query('SELECT NOW')
await delay(50)
await client.end()
assert(cli.native || errorHit)

// further queries on the client should fail since its in an invalid state
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')

await closeServer()
})

Expand All @@ -122,6 +120,10 @@ suite.testAsync('Out of order parseComplete on extended query is catchable', asy
await client.query('SELECT $1', ['foo'])
await delay(40)
assert(cli.native || errorHit)

// further queries on the client should fail since its in an invalid state
await assert.rejects(() => client.query('SELECTR NOW()'), 'Further queries on the client should reject')

await client.end()

await closeServer()
Expand All @@ -142,6 +144,9 @@ suite.testAsync('Out of order parseComplete on pool is catchable', async () => {
await delay(100)
assert(cli.native || errorHit)

assert.strictEqual(pool.idleCount, 0, 'Pool should have no idle clients')
assert.strictEqual(pool.totalCount, 0, 'Pool should have no connected clients')

await pool.end()
await closeServer()
})

0 comments on commit 54dc7af

Please sign in to comment.