Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed Aug 12, 2024
1 parent 2d67ef6 commit 50306bc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
4 changes: 2 additions & 2 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class Client extends EventEmitter {

_handleCommandComplete(msg) {
if (this.activeQuery == null) {
const error = new Error('Received unexpected commandComplete message from backend.')
const error = new Error('Received unexpected commandComplete message from backend.')
this._handleErrorEvent(error)
return
}
Expand All @@ -388,7 +388,7 @@ class Client extends EventEmitter {

_handleParseComplete() {
if (this.activeQuery == null) {
const error = new Error('Received unexpected parseComplete message from backend.')
const error = new Error('Received unexpected parseComplete message from backend.')
this._handleErrorEvent(error)
return
}
Expand Down
102 changes: 50 additions & 52 deletions packages/pg/test/integration/gh-issues/3174-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,75 +84,73 @@ const delay = (ms) =>
})

const testErrorBuffer = (bufferName, errorBuffer) => {
suite.testAsync(`Out of order ${bufferName} on simple query is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
})
const client = new helper.Client(options)
await client.connect()

suite.testAsync(`Out of order ${bufferName} on simple query is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
})
const client = new helper.Client(options)
await client.connect()

let errorHit = false
client.on('error', () => {
errorHit = true
})

await client.query('SELECT NOW()')
await delay(50)
assert(cli.native || errorHit)
let errorHit = false
client.on('error', () => {
errorHit = true
})

// 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.query('SELECT NOW()')
await delay(50)
assert(cli.native || errorHit)

await closeServer()
})
// 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')

suite.testAsync(`Out of order ${bufferName} on extended query is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
await closeServer()
})
const client = new helper.Client(options)
await client.connect()

let errorHit = false
client.on('error', () => {
errorHit = true
})
suite.testAsync(`Out of order ${bufferName} on extended query is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
})
const client = new helper.Client(options)
await client.connect()

await client.query('SELECT $1', ['foo'])
await delay(40)
assert(cli.native || errorHit)
let errorHit = false
client.on('error', () => {
errorHit = true
})

// 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.query('SELECT $1', ['foo'])
await delay(40)
assert(cli.native || errorHit)

await client.end()
// 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()
})
await client.end()

suite.testAsync(`Out of order ${bufferName} on pool is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
await closeServer()
})
const pool = new helper.pg.Pool(options)

let errorHit = false
pool.on('error', () => {
errorHit = true
})
suite.testAsync(`Out of order ${bufferName} on pool is catchable`, async () => {
const closeServer = await new Promise((resolve, reject) => {
return startMockServer(options.port, errorBuffer, (closeServer) => resolve(closeServer))
})
const pool = new helper.pg.Pool(options)

await pool.query('SELECT $1', ['foo'])
await delay(100)
assert(cli.native || errorHit)
let errorHit = false
pool.on('error', () => {
errorHit = true
})

assert.strictEqual(pool.idleCount, 0, 'Pool should have no idle clients')
assert.strictEqual(pool.totalCount, 0, 'Pool should have no connected clients')
await pool.query('SELECT $1', ['foo'])
await delay(100)
assert(cli.native || errorHit)

await pool.end()
await closeServer()
})
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()
})
}

testErrorBuffer('parseComplete', buffers.parseComplete())
Expand Down

0 comments on commit 50306bc

Please sign in to comment.