@@ -95,4 +95,66 @@ test('COPY TO, queue queries', function () {
95
95
} ) ;
96
96
} ) ;
97
97
} ) ;
98
+ test ( "COPY TO incorrect usage with large data" , function ( ) {
99
+ //when many data is loaded from database (and it takes a lot of time)
100
+ //there are chance, that query will be canceled before it ends
101
+ //but if there are not so much data, cancel message may be
102
+ //send after copy query ends
103
+ //so we need to test both situations
104
+ pg . connect ( helper . config , function ( error , client ) {
105
+ assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
106
+ //intentionally incorrect usage of copy.
107
+ //this has to report error in standart way, instead of just throwing exception
108
+ client . query (
109
+ "COPY (SELECT GENERATE_SERIES(1, 10000000)) TO STDOUT WITH CSV" ,
110
+ assert . calls ( function ( error ) {
111
+ assert . ok ( error , "error should be reported when sending copy to query with query method" ) ;
112
+ client . query ( "SELECT 1" , assert . calls ( function ( error , result ) {
113
+ assert . isNull ( error , "incorrect copy usage should not break connection" ) ;
114
+ assert . ok ( result , "incorrect copy usage should not break connection" ) ;
115
+ pg . end ( helper . config ) ;
116
+ } ) ) ;
117
+ } )
118
+ ) ;
119
+ } ) ;
120
+ } ) ;
121
+ test ( "COPY TO incorrect usage with small data" , function ( ) {
122
+ pg . connect ( helper . config , function ( error , client ) {
123
+ assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
124
+ //intentionally incorrect usage of copy.
125
+ //this has to report error in standart way, instead of just throwing exception
126
+ client . query (
127
+ "COPY (SELECT GENERATE_SERIES(1, 1)) TO STDOUT WITH CSV" ,
128
+ assert . calls ( function ( error ) {
129
+ assert . ok ( error , "error should be reported when sending copy to query with query method" ) ;
130
+ client . query ( "SELECT 1" , assert . calls ( function ( error , result ) {
131
+ assert . isNull ( error , "incorrect copy usage should not break connection" ) ;
132
+ assert . ok ( result , "incorrect copy usage should not break connection" ) ;
133
+ pg . end ( helper . config ) ;
134
+ } ) ) ;
135
+ } )
136
+ ) ;
137
+ } ) ;
138
+ } ) ;
139
+
140
+ test ( "COPY FROM incorrect usage" , function ( ) {
141
+ pg . connect ( helper . config , function ( error , client ) {
142
+ assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
143
+ prepareTable ( client , function ( ) {
144
+ //intentionally incorrect usage of copy.
145
+ //this has to report error in standart way, instead of just throwing exception
146
+ client . query (
147
+ "COPY copy_test from STDIN WITH CSV" ,
148
+ assert . calls ( function ( error ) {
149
+ assert . ok ( error , "error should be reported when sending copy to query with query method" ) ;
150
+ client . query ( "SELECT 1" , assert . calls ( function ( error , result ) {
151
+ assert . isNull ( error , "incorrect copy usage should not break connection" ) ;
152
+ assert . ok ( result , "incorrect copy usage should not break connection" ) ;
153
+ pg . end ( helper . config ) ;
154
+ } ) ) ;
155
+ } )
156
+ ) ;
157
+ } ) ;
158
+ } ) ;
159
+ } ) ;
98
160
0 commit comments