@@ -10,18 +10,19 @@ process.on('unhandledRejection', function (e) {
1010
1111const suite = new helper . Suite ( )
1212
13- // Test that result size exceeding maxResultSize properly raises an error
1413suite . 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+
1518 // Create a pool with a very small result size limit
1619 const pool = new pg . Pool ( {
1720 maxResultSize : 100 , // Very small limit (100 bytes)
1821 ...helper . args ,
1922 } )
2023
21- // Track if we've seen the size exceeded error
2224 let sizeExceededErrorSeen = false
2325
24- // Set up error handler on pool
2526 pool . on ( 'error' , ( err ) => {
2627 console . log ( 'Pool error:' , err . message , err . code )
2728 } )
@@ -33,21 +34,20 @@ suite.test('maxResultSize limit triggers error', (cb) => {
3334 client . on ( 'error' , ( err ) => {
3435 console . log ( 'Client error event:' , err . message , err . code )
3536
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' ) {
3940 sizeExceededErrorSeen = true
4041 }
4142 } )
4243
43- // Create a temp table
4444 return client
4545 . query ( 'CREATE TEMP TABLE large_result_test(id SERIAL, data TEXT)' )
4646 . then ( ( ) => {
47- // Insert data that will exceed the size limit when selected
47+ // Insert rows that will exceed the size limit when queried
4848 const insertPromises = [ ]
4949 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
5151 const data = 'x' . repeat ( 50 )
5252 insertPromises . push ( client . query ( 'INSERT INTO large_result_test(data) VALUES($1)' , [ data ] ) )
5353 }
@@ -56,7 +56,6 @@ suite.test('maxResultSize limit triggers error', (cb) => {
5656 . then ( ( ) => {
5757 console . log ( 'Running query that should exceed size limit...' )
5858
59- // This query should fail due to exceeding size limit
6059 return client
6160 . query ( 'SELECT * FROM large_result_test' )
6261 . then ( ( ) => {
@@ -65,15 +64,14 @@ suite.test('maxResultSize limit triggers error', (cb) => {
6564 . catch ( ( err ) => {
6665 console . log ( 'Query error caught:' , err . message , err . code )
6766
68- // The error should have the correct code
67+ // Both implementations should throw an error with this code
6968 assert . equal ( err . code , 'RESULT_SIZE_EXCEEDED' , 'Error should have RESULT_SIZE_EXCEEDED code' )
7069
71- // Give a little time for error events to be processed
70+ // Give time for error events to propagate
7271 return new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) . then ( ( ) => {
73- // Verify we saw the expected error event
72+ // Verify we saw the error event
7473 assert ( sizeExceededErrorSeen , 'Should have seen the size exceeded error event' )
7574
76- // Attempt cleanup but don't fail if it errors
7775 return client . query ( 'DROP TABLE IF EXISTS large_result_test' ) . catch ( ( ) => {
7876 /* ignore cleanup errors */
7977 } )
@@ -85,16 +83,17 @@ suite.test('maxResultSize limit triggers error', (cb) => {
8583 pool . end ( cb )
8684 } )
8785 . catch ( ( err ) => {
86+ console . error ( 'Test error:' , err . message )
8887 client . release ( )
8988 pool . end ( ( ) => cb ( err ) )
9089 } )
9190 } )
9291 . catch ( ( err ) => {
92+ console . error ( 'Connection error:' , err . message )
9393 pool . end ( ( ) => cb ( err ) )
9494 } )
9595} )
9696
97- // Test that results under the maxResultSize limit work normally
9897suite . test ( 'results under maxResultSize limit work correctly' , ( cb ) => {
9998 // Create a pool with a reasonably large limit
10099 const pool = new pg . Pool ( {
@@ -105,21 +104,16 @@ suite.test('results under maxResultSize limit work correctly', (cb) => {
105104 pool
106105 . connect ( )
107106 . then ( ( client ) => {
108- // Create a temp table
109107 return client
110108 . query ( 'CREATE TEMP TABLE small_result_test(id SERIAL, data TEXT)' )
111109 . then ( ( ) => {
112- // Insert a small amount of data
113110 return client . query ( 'INSERT INTO small_result_test(data) VALUES($1)' , [ 'small_data' ] )
114111 } )
115112 . then ( ( ) => {
116- // This query should succeed
117113 return client . query ( 'SELECT * FROM small_result_test' ) . then ( ( result ) => {
118- // Verify the result
119114 assert . equal ( result . rows . length , 1 , 'Should get 1 row' )
120115 assert . equal ( result . rows [ 0 ] . data , 'small_data' , 'Data should match' )
121116
122- // Clean up
123117 return client . query ( 'DROP TABLE small_result_test' )
124118 } )
125119 } )
0 commit comments