Skip to content

Commit 65d85d5

Browse files
committed
chore: add max-result-size integration test
1 parent 4734dfa commit 65d85d5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict'
2+
var helper = require('./test-helper')
3+
var assert = require('assert')
4+
5+
const pool = new helper.pg.Pool({
6+
maxResultSize: 100, // Very small size limit (100 bytes)
7+
// Keep other connection parameters from helper
8+
...helper.args
9+
})
10+
11+
// Flag to track if we've seen the first type of error message
12+
let sizeExceededErrorSeen = false
13+
14+
pool.connect(
15+
assert.success(function (client) {
16+
// First create a temp table
17+
client.query('CREATE TEMP TABLE large_result_test(id SERIAL, data TEXT)', assert.success(function () {
18+
// Insert data that will exceed the size limit when selected
19+
const insertPromises = []
20+
for (let i = 0; i < 20; i++) {
21+
// Each row will have 50 bytes of data
22+
const data = 'x'.repeat(50)
23+
insertPromises.push(
24+
client.query('INSERT INTO large_result_test(data) VALUES($1)', [data])
25+
)
26+
}
27+
28+
// After inserting all rows, attempt to select them all
29+
Promise.all(insertPromises)
30+
.then(function () {
31+
client.on('error', (err) => {
32+
// If we see the first error type, mark it
33+
if (err.message === 'Query result size exceeded the configured limit') {
34+
assert.equal(err.code, 'RESULT_SIZE_EXCEEDED', 'Size exceeded error should have RESULT_SIZE_EXCEEDED code')
35+
sizeExceededErrorSeen = true
36+
}
37+
38+
// For the second error type, we just verify it happens after we've seen the first type
39+
if (err.message === 'Received unexpected commandComplete message from backend.') {
40+
assert(sizeExceededErrorSeen, 'Should have seen size exceeded error before commandComplete error')
41+
}
42+
})
43+
44+
// This query should fail due to exceeding size limit
45+
client.query('SELECT * FROM large_result_test')
46+
.then(function (_result) {
47+
throw new Error('Query should have failed due to size limit')
48+
})
49+
.catch(function (err) {
50+
assert.equal(err.code, 'RESULT_SIZE_EXCEEDED', 'Query error should have RESULT_SIZE_EXCEEDED code')
51+
})
52+
})
53+
}))
54+
})
55+
)

0 commit comments

Comments
 (0)