@@ -447,6 +447,144 @@ describe('#stub-direct direct driver with stub server', () => {
447447 } )
448448 } )
449449
450+ describe ( 'should allow to change fetch size' , ( ) => {
451+ async function verifyFailureOnCommit ( version ) {
452+ if ( ! boltStub . supported ) {
453+ return
454+ }
455+
456+ const server = await boltStub . start (
457+ `./test/resources/boltstub/${ version } /read_in_batch.script` ,
458+ 9001
459+ )
460+
461+ const driver = boltStub . newDriver ( 'bolt://127.0.0.1:9001' , {
462+ fetchSize : 2
463+ } )
464+ const session = driver . session ( { defaultAccessMode : READ } )
465+
466+ const result = await session . run ( 'MATCH (n) RETURN n.name' )
467+ const records = result . records
468+ expect ( records . length ) . toEqual ( 3 )
469+ expect ( records [ 0 ] . get ( 0 ) ) . toBe ( 'Bob' )
470+ expect ( records [ 1 ] . get ( 0 ) ) . toBe ( 'Alice' )
471+ expect ( records [ 2 ] . get ( 0 ) ) . toBe ( 'Tina' )
472+
473+ const connectionKey = Object . keys ( openConnections ( driver ) ) [ 0 ]
474+ expect ( connectionKey ) . toBeTruthy ( )
475+
476+ const connection = openConnections ( driver , connectionKey )
477+ await session . close ( )
478+
479+ // generate a fake fatal error
480+ connection . _handleFatalError (
481+ newError ( 'connection reset' , SERVICE_UNAVAILABLE )
482+ )
483+
484+ // expect that the connection to be removed from the pool
485+ expect ( connectionPool ( driver , '127.0.0.1:9001' ) . length ) . toEqual ( 0 )
486+ expect ( activeResources ( driver , '127.0.0.1:9001' ) ) . toBeFalsy ( )
487+ // expect that the connection to be unregistered from the open connections registry
488+ expect ( openConnections ( driver , connectionKey ) ) . toBeFalsy ( )
489+
490+ await driver . close ( )
491+ await server . exit ( )
492+ }
493+
494+ it ( 'v4' , ( ) => verifyFailureOnCommit ( 'v4' ) )
495+ } )
496+
497+ describe ( 'should stream in many batches' , ( ) => {
498+ async function verifyFailureOnCommit ( version ) {
499+ if ( ! boltStub . supported ) {
500+ return
501+ }
502+
503+ const server = await boltStub . start (
504+ `./test/resources/boltstub/${ version } /read_in_batch.script` ,
505+ 9001
506+ )
507+
508+ const driver = boltStub . newDriver ( 'bolt://127.0.0.1:9001' )
509+ const session = driver . session ( { defaultAccessMode : READ , fetchSize : 2 } )
510+
511+ const result = await session . run ( 'MATCH (n) RETURN n.name' )
512+ const records = result . records
513+ expect ( records . length ) . toEqual ( 3 )
514+ expect ( records [ 0 ] . get ( 0 ) ) . toBe ( 'Bob' )
515+ expect ( records [ 1 ] . get ( 0 ) ) . toBe ( 'Alice' )
516+ expect ( records [ 2 ] . get ( 0 ) ) . toBe ( 'Tina' )
517+
518+ const connectionKey = Object . keys ( openConnections ( driver ) ) [ 0 ]
519+ expect ( connectionKey ) . toBeTruthy ( )
520+
521+ const connection = openConnections ( driver , connectionKey )
522+ await session . close ( )
523+
524+ // generate a fake fatal error
525+ connection . _handleFatalError (
526+ newError ( 'connection reset' , SERVICE_UNAVAILABLE )
527+ )
528+
529+ // expect that the connection to be removed from the pool
530+ expect ( connectionPool ( driver , '127.0.0.1:9001' ) . length ) . toEqual ( 0 )
531+ expect ( activeResources ( driver , '127.0.0.1:9001' ) ) . toBeFalsy ( )
532+ // expect that the connection to be unregistered from the open connections registry
533+ expect ( openConnections ( driver , connectionKey ) ) . toBeFalsy ( )
534+
535+ await driver . close ( )
536+ await server . exit ( )
537+ }
538+
539+ it ( 'v4' , ( ) => verifyFailureOnCommit ( 'v4' ) )
540+ } )
541+
542+ describe ( 'should ignore fetchSize setting' , ( ) => {
543+ async function verifyFailureOnCommit ( version ) {
544+ if ( ! boltStub . supported ) {
545+ return
546+ }
547+
548+ const server = await boltStub . start (
549+ `./test/resources/boltstub/${ version } /read.script` ,
550+ 9001
551+ )
552+
553+ const driver = boltStub . newDriver ( 'bolt://127.0.0.1:9001' )
554+ const session = driver . session ( { defaultAccessMode : READ , fetchSize : 2 } )
555+
556+ const result = await session . run ( 'MATCH (n) RETURN n.name' )
557+ const records = result . records
558+ expect ( records . length ) . toEqual ( 3 )
559+ expect ( records [ 0 ] . get ( 0 ) ) . toBe ( 'Bob' )
560+ expect ( records [ 1 ] . get ( 0 ) ) . toBe ( 'Alice' )
561+ expect ( records [ 2 ] . get ( 0 ) ) . toBe ( 'Tina' )
562+
563+ const connectionKey = Object . keys ( openConnections ( driver ) ) [ 0 ]
564+ expect ( connectionKey ) . toBeTruthy ( )
565+
566+ const connection = openConnections ( driver , connectionKey )
567+ await session . close ( )
568+
569+ // generate a fake fatal error
570+ connection . _handleFatalError (
571+ newError ( 'connection reset' , SERVICE_UNAVAILABLE )
572+ )
573+
574+ // expect that the connection to be removed from the pool
575+ expect ( connectionPool ( driver , '127.0.0.1:9001' ) . length ) . toEqual ( 0 )
576+ expect ( activeResources ( driver , '127.0.0.1:9001' ) ) . toBeFalsy ( )
577+ // expect that the connection to be unregistered from the open connections registry
578+ expect ( openConnections ( driver , connectionKey ) ) . toBeFalsy ( )
579+
580+ await driver . close ( )
581+ await server . exit ( )
582+ }
583+
584+ it ( 'v3' , ( ) => verifyFailureOnCommit ( 'v3' ) )
585+ it ( 'v2' , ( ) => verifyFailureOnCommit ( 'v2' ) )
586+ } )
587+
450588 function connectionPool ( driver , key ) {
451589 return driver . _connectionProvider . _connectionPool . _pools [ key ]
452590 }
0 commit comments