File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -316,7 +316,9 @@ export class SQLiteCloudConnection {
316316
317317 this . socket ?. write ( commands , 'utf8' , ( ) => {
318318 socketTimeout = setTimeout ( ( ) => {
319- finish ( new SQLiteCloudError ( 'Request timed out' , { cause : anonimizeCommand ( commands ) } ) )
319+ const timeoutError = new SQLiteCloudError ( 'Request timed out' , { cause : anonimizeCommand ( commands ) } )
320+ this . log ( `Request timed out, config.timeout is ${ this . config . timeout } ms` , timeoutError )
321+ finish ( timeoutError )
320322 } , this . config . timeout )
321323 this . socket ?. on ( 'data' , readData )
322324 } )
Original file line number Diff line number Diff line change @@ -255,16 +255,21 @@ describe('connection', () => {
255255 it (
256256 'should test chunked rowset' ,
257257 done => {
258- chinook . verbose ( )
259- chinook . sendCommands ( 'TEST ROWSET_CHUNK' , ( error , results ) => {
258+ // this operation sends 150 packets, so we need to increase the timeout
259+ const database = getChinookConnection ( undefined , { timeout : 120 * 1000 } )
260+
261+ database . verbose ( )
262+ database . sendCommands ( 'TEST ROWSET_CHUNK' , ( error , results ) => {
260263 expect ( error ) . toBeNull ( )
261264 expect ( results . numberOfRows ) . toBe ( 147 )
262265 expect ( results . numberOfColumns ) . toBe ( 1 )
263266 expect ( results . columnsNames ) . toEqual ( [ 'key' ] )
267+
268+ database . close ( )
264269 done ( )
265270 } )
266271 } ,
267- 3 * LONG_TIMEOUT
272+ LONG_TIMEOUT
268273 )
269274 } )
270275
@@ -288,6 +293,20 @@ describe('connection', () => {
288293 } )
289294 }
290295 } )
296+
297+ it ( 'should apply short timeout' , done => {
298+ const database = getChinookConnection ( undefined , { timeout : 200 } )
299+ database . verbose ( )
300+
301+ // this operation sends 150 packets and cannot complete in 200ms
302+ database . sendCommands ( 'TEST ROWSET_CHUNK' , ( error , results ) => {
303+ expect ( error ) . toBeInstanceOf ( SQLiteCloudError )
304+ expect ( ( error as any ) . message ) . toBe ( 'Request timed out' )
305+
306+ database . close ( )
307+ done ( )
308+ } )
309+ } )
291310 } )
292311
293312 describe ( 'send select commands' , ( ) => {
You can’t perform that action at this time.
0 commit comments