@@ -10,18 +10,19 @@ process.on('unhandledRejection', function (e) {
10
10
11
11
const suite = new helper . Suite ( )
12
12
13
- // Test that result size exceeding maxResultSize properly raises an error
14
13
suite . test ( 'maxResultSize limit triggers error' , ( cb ) => {
14
+ // Check if we're running with the native client
15
+ const isNative = helper . args . native
16
+ console . log ( isNative ? 'Testing with native client' : 'Testing with JavaScript client' )
17
+
15
18
// Create a pool with a very small result size limit
16
19
const pool = new pg . Pool ( {
17
20
maxResultSize : 100 , // Very small limit (100 bytes)
18
21
...helper . args ,
19
22
} )
20
23
21
- // Track if we've seen the size exceeded error
22
24
let sizeExceededErrorSeen = false
23
25
24
- // Set up error handler on pool
25
26
pool . on ( 'error' , ( err ) => {
26
27
console . log ( 'Pool error:' , err . message , err . code )
27
28
} )
@@ -33,21 +34,20 @@ suite.test('maxResultSize limit triggers error', (cb) => {
33
34
client . on ( 'error' , ( err ) => {
34
35
console . log ( 'Client error event:' , err . message , err . code )
35
36
36
- // If we get the expected error, mark it
37
- if ( err . message === 'Query result size exceeded the configured limit' ) {
38
- assert . equal ( err . code , 'RESULT_SIZE_EXCEEDED' , 'Error should have RESULT_SIZE_EXCEEDED code' )
37
+ // If we get any size exceeded error, mark it
38
+ if ( err . code === 'RESULT_SIZE_EXCEEDED' ||
39
+ err . message === 'Query result size exceeded the configured limit' ) {
39
40
sizeExceededErrorSeen = true
40
41
}
41
42
} )
42
43
43
- // Create a temp table
44
44
return client
45
45
. query ( 'CREATE TEMP TABLE large_result_test(id SERIAL, data TEXT)' )
46
46
. then ( ( ) => {
47
- // Insert data that will exceed the size limit when selected
47
+ // Insert rows that will exceed the size limit when queried
48
48
const insertPromises = [ ]
49
49
for ( let i = 0 ; i < 20 ; i ++ ) {
50
- // Each row will have 50 bytes of data
50
+ // Each row will have enough data to eventually exceed our limit
51
51
const data = 'x' . repeat ( 50 )
52
52
insertPromises . push ( client . query ( 'INSERT INTO large_result_test(data) VALUES($1)' , [ data ] ) )
53
53
}
@@ -56,7 +56,6 @@ suite.test('maxResultSize limit triggers error', (cb) => {
56
56
. then ( ( ) => {
57
57
console . log ( 'Running query that should exceed size limit...' )
58
58
59
- // This query should fail due to exceeding size limit
60
59
return client
61
60
. query ( 'SELECT * FROM large_result_test' )
62
61
. then ( ( ) => {
@@ -65,15 +64,14 @@ suite.test('maxResultSize limit triggers error', (cb) => {
65
64
. catch ( ( err ) => {
66
65
console . log ( 'Query error caught:' , err . message , err . code )
67
66
68
- // The error should have the correct code
67
+ // Both implementations should throw an error with this code
69
68
assert . equal ( err . code , 'RESULT_SIZE_EXCEEDED' , 'Error should have RESULT_SIZE_EXCEEDED code' )
70
69
71
- // Give a little time for error events to be processed
70
+ // Give time for error events to propagate
72
71
return new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) . then ( ( ) => {
73
- // Verify we saw the expected error event
72
+ // Verify we saw the error event
74
73
assert ( sizeExceededErrorSeen , 'Should have seen the size exceeded error event' )
75
74
76
- // Attempt cleanup but don't fail if it errors
77
75
return client . query ( 'DROP TABLE IF EXISTS large_result_test' ) . catch ( ( ) => {
78
76
/* ignore cleanup errors */
79
77
} )
@@ -85,16 +83,17 @@ suite.test('maxResultSize limit triggers error', (cb) => {
85
83
pool . end ( cb )
86
84
} )
87
85
. catch ( ( err ) => {
86
+ console . error ( 'Test error:' , err . message )
88
87
client . release ( )
89
88
pool . end ( ( ) => cb ( err ) )
90
89
} )
91
90
} )
92
91
. catch ( ( err ) => {
92
+ console . error ( 'Connection error:' , err . message )
93
93
pool . end ( ( ) => cb ( err ) )
94
94
} )
95
95
} )
96
96
97
- // Test that results under the maxResultSize limit work normally
98
97
suite . test ( 'results under maxResultSize limit work correctly' , ( cb ) => {
99
98
// Create a pool with a reasonably large limit
100
99
const pool = new pg . Pool ( {
@@ -105,21 +104,16 @@ suite.test('results under maxResultSize limit work correctly', (cb) => {
105
104
pool
106
105
. connect ( )
107
106
. then ( ( client ) => {
108
- // Create a temp table
109
107
return client
110
108
. query ( 'CREATE TEMP TABLE small_result_test(id SERIAL, data TEXT)' )
111
109
. then ( ( ) => {
112
- // Insert a small amount of data
113
110
return client . query ( 'INSERT INTO small_result_test(data) VALUES($1)' , [ 'small_data' ] )
114
111
} )
115
112
. then ( ( ) => {
116
- // This query should succeed
117
113
return client . query ( 'SELECT * FROM small_result_test' ) . then ( ( result ) => {
118
- // Verify the result
119
114
assert . equal ( result . rows . length , 1 , 'Should get 1 row' )
120
115
assert . equal ( result . rows [ 0 ] . data , 'small_data' , 'Data should match' )
121
116
122
- // Clean up
123
117
return client . query ( 'DROP TABLE small_result_test' )
124
118
} )
125
119
} )
0 commit comments