@@ -4,85 +4,92 @@ var assert = require('assert')
4
4
const { Client } = helper . pg
5
5
const suite = new helper . Suite ( )
6
6
7
-
8
7
// Basic test to check if the _maxResultSize property is passed to Connection
9
8
suite . test ( 'client passes maxResultSize to connection' , function ( done ) {
10
9
var client = new Client ( {
11
10
...helper . args ,
12
- maxResultSize : 1024 * 1024 // 1MB limit
11
+ maxResultSize : 1024 * 1024 , // 1MB limit
13
12
} )
14
-
15
- client . connect ( assert . success ( function ( ) {
16
- assert . equal ( client . connection . _maxResultSize , 1024 * 1024 ,
17
- 'maxResultSize should be passed to the connection' )
18
- client . end ( done )
19
- } ) )
13
+
14
+ client . connect (
15
+ assert . success ( function ( ) {
16
+ assert . equal ( client . connection . _maxResultSize , 1024 * 1024 , 'maxResultSize should be passed to the connection' )
17
+ client . end ( done )
18
+ } )
19
+ )
20
20
} )
21
21
22
22
// Check if the correct attachListeners method is being used based on maxResultSize
23
23
suite . test ( 'connection uses correct listener implementation' , function ( done ) {
24
24
var client = new Client ( {
25
25
...helper . args ,
26
- maxResultSize : 1024 * 1024 // 1MB limit
26
+ maxResultSize : 1024 * 1024 , // 1MB limit
27
27
} )
28
-
29
- client . connect ( assert . success ( function ( ) {
30
- // Just a simple check to see if our methods exist on the connection object
31
- assert ( typeof client . connection . _attachListenersStandard === 'function' ,
32
- 'Standard listener method should exist' )
33
- assert ( typeof client . connection . _attachListenersWithSizeLimit === 'function' ,
34
- 'Size-limiting listener method should exist' )
35
- client . end ( done )
36
- } ) )
28
+
29
+ client . connect (
30
+ assert . success ( function ( ) {
31
+ // Just a simple check to see if our methods exist on the connection object
32
+ assert ( typeof client . connection . _attachListenersStandard === 'function' , 'Standard listener method should exist' )
33
+ assert (
34
+ typeof client . connection . _attachListenersWithSizeLimit === 'function' ,
35
+ 'Size-limiting listener method should exist'
36
+ )
37
+ client . end ( done )
38
+ } )
39
+ )
37
40
} )
38
41
39
42
// Test that small result sets complete successfully with maxResultSize set
40
43
suite . test ( 'small result with maxResultSize' , function ( done ) {
41
44
var client = new Client ( {
42
45
...helper . args ,
43
- maxResultSize : 1024 * 1024 // 1MB limit
46
+ maxResultSize : 1024 * 1024 , // 1MB limit
44
47
} )
45
-
46
- client . connect ( assert . success ( function ( ) {
47
- client . query ( 'SELECT generate_series(1, 10) as num' , assert . success ( function ( result ) {
48
- assert . equal ( result . rows . length , 10 )
49
- client . end ( done )
50
- } ) )
51
- } ) )
48
+
49
+ client . connect (
50
+ assert . success ( function ( ) {
51
+ client . query (
52
+ 'SELECT generate_series(1, 10) as num' ,
53
+ assert . success ( function ( result ) {
54
+ assert . equal ( result . rows . length , 10 )
55
+ client . end ( done )
56
+ } )
57
+ )
58
+ } )
59
+ )
52
60
} )
53
61
54
62
// Test for large result size
55
63
// Using a separate test to avoid issue with callback being called twice
56
64
suite . testAsync ( 'large result triggers error' , async ( ) => {
57
65
const client = new Client ( {
58
66
...helper . args ,
59
- maxResultSize : 500 // Very small limit
67
+ maxResultSize : 500 , // Very small limit
60
68
} )
61
69
62
70
// Setup error handler
63
- const errorPromise = new Promise ( resolve => {
64
- client . on ( 'error' , err => {
71
+ const errorPromise = new Promise ( ( resolve ) => {
72
+ client . on ( 'error' , ( err ) => {
65
73
assert . equal ( err . message , 'Query result size exceeded the configured limit' )
66
74
assert . equal ( err . code , 'RESULT_SIZE_EXCEEDED' )
67
75
resolve ( )
68
76
} )
69
77
} )
70
78
71
79
await client . connect ( )
72
-
80
+
73
81
// Start the query but don't await it (it will error)
74
- const queryPromise = client . query ( 'SELECT repeat(\'x\', 1000) as data FROM generate_series(1, 100)' )
75
- . catch ( ( ) => {
76
- // We expect this to error out, silence the rejection
77
- return null
78
- } )
79
-
82
+ const queryPromise = client . query ( "SELECT repeat('x', 1000) as data FROM generate_series(1, 100)" ) . catch ( ( ) => {
83
+ // We expect this to error out, silence the rejection
84
+ return null
85
+ } )
86
+
80
87
// Wait for error event
81
88
await errorPromise
82
-
89
+
83
90
// Make sure the query is done before we end
84
91
await queryPromise
85
-
92
+
86
93
// Clean up
87
94
await client . end ( ) . catch ( ( ) => { } )
88
- } )
95
+ } )
0 commit comments