Skip to content

Commit 65e7882

Browse files
committed
chore: setup e2e test for invalid packet error handling
1 parent 0089a69 commit 65e7882

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Diff for: packages/pg/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"pg-connection-string": "^2.7.0",
2424
"pg-pool": "^3.8.0",
25-
"pg-protocol": "^1.8.0",
25+
"pg-protocol": "file:../pg-protocol",
2626
"pg-types": "^2.1.0",
2727
"pgpass": "1.x"
2828
},

Diff for: packages/pg/test/integration/connection-pool/error-tests.js

+28
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,31 @@ suite.test('handles socket error during pool.query and destroys it immediately',
164164
}, 100)
165165
}
166166
})
167+
168+
suite.test('unexpected handling packet error emit catchable errors', () => {
169+
const pool = new pg.Pool()
170+
pool.connect(
171+
assert.success((client, done) => {
172+
client.once(
173+
'error',
174+
// After unexpected packed error, the client will receive an unexpected commandComplete message from backend
175+
assert.calls((err) => {
176+
assert.equal(`${err}`, 'Error: Received unexpected commandComplete message from backend.')
177+
done()
178+
})
179+
)
180+
client.query(
181+
// Retrieve a field which lenght cannot be handled by JS (+700Mo string)
182+
`SELECT repeat('A', 536870889)`,
183+
assert.calls((err) => {
184+
if (helper.args.native) {
185+
assert.ok(err)
186+
} else {
187+
assert.equal(err.message, 'unexpected error handling packet: Error: Cannot create a string longer than 0x1fffffe8 characters')
188+
assert.equal(err.length, 536870899)
189+
}
190+
})
191+
)
192+
})
193+
)
194+
})

0 commit comments

Comments
 (0)