@@ -1466,27 +1466,44 @@ describe('routing driver', () => {
14661466 }
14671467
14681468 const kit = new boltkit . BoltKit ( ) ;
1469- const router1 = kit . start ( './test/resources/boltkit/acquire_endpoints.script' , 9010 ) ;
1469+ // use scripts that exit eagerly when they are executed to simulate failed servers
1470+ const router1 = kit . start ( './test/resources/boltkit/acquire_endpoints_and_exit.script' , 9010 ) ;
1471+ const tmpReader = kit . start ( './test/resources/boltkit/read_server_and_exit.script' , 9005 ) ;
14701472
14711473 kit . run ( ( ) => {
14721474 const driver = newDriver ( 'bolt+routing://127.0.0.1:9010' ) ;
1473- const session = driver . session ( ) ;
14741475
1475- // restart router on the same port with different script that contains itself as reader
1476- router1 . exit ( ( ) => {
1477- const router2 = kit . start ( './test/resources/boltkit/rediscover_using_initial_router.script' , 9010 ) ;
1478-
1479- session . readTransaction ( tx => tx . run ( 'MATCH (n) RETURN n.name AS name' ) ) . then ( result => {
1480- const records = result . records ;
1481- expect ( records . length ) . toEqual ( 2 ) ;
1482- expect ( records [ 0 ] . get ( 'name' ) ) . toEqual ( 'Bob' ) ;
1483- expect ( records [ 1 ] . get ( 'name' ) ) . toEqual ( 'Alice' ) ;
1476+ // run a dummy query to force routing table initialization
1477+ const session = driver . session ( READ ) ;
1478+ session . run ( 'MATCH (n) RETURN n.name' ) . then ( result => {
1479+ expect ( result . records . length ) . toEqual ( 3 ) ;
1480+ session . close ( ( ) => {
1481+ // stop existing router and reader
1482+ router1 . exit ( code1 => {
1483+ tmpReader . exit ( code2 => {
1484+ // at this point previously used router and reader should be dead
1485+ expect ( code1 ) . toEqual ( 0 ) ;
1486+ expect ( code2 ) . toEqual ( 0 ) ;
14841487
1485- session . close ( ( ) => {
1486- driver . close ( ) ;
1487- router2 . exit ( code => {
1488- expect ( code ) . toEqual ( 0 ) ;
1489- done ( ) ;
1488+ // start new router on the same port with different script that contains itself as reader
1489+ const router2 = kit . start ( './test/resources/boltkit/rediscover_using_initial_router.script' , 9010 ) ;
1490+
1491+ kit . run ( ( ) => {
1492+ session . readTransaction ( tx => tx . run ( 'MATCH (n) RETURN n.name AS name' ) ) . then ( result => {
1493+ const records = result . records ;
1494+ expect ( records . length ) . toEqual ( 2 ) ;
1495+ expect ( records [ 0 ] . get ( 'name' ) ) . toEqual ( 'Bob' ) ;
1496+ expect ( records [ 1 ] . get ( 'name' ) ) . toEqual ( 'Alice' ) ;
1497+
1498+ session . close ( ( ) => {
1499+ driver . close ( ) ;
1500+ router2 . exit ( code => {
1501+ expect ( code ) . toEqual ( 0 ) ;
1502+ done ( ) ;
1503+ } ) ;
1504+ } ) ;
1505+ } ) ;
1506+ } ) ;
14901507 } ) ;
14911508 } ) ;
14921509 } ) ;
@@ -1502,28 +1519,28 @@ describe('routing driver', () => {
15021519
15031520 const kit = new boltkit . BoltKit ( ) ;
15041521 const router1 = kit . start ( './test/resources/boltkit/acquire_endpoints.script' , 9010 ) ;
1522+ // start new router on a different port to emulate host name resolution
1523+ // this router uses different script that contains itself as reader
1524+ const router2 = kit . start ( './test/resources/boltkit/rediscover_using_initial_router.script' , 9009 ) ;
15051525
15061526 kit . run ( ( ) => {
15071527 const driver = newDriver ( 'bolt+routing://127.0.0.1:9010' ) ;
15081528 // make seed address resolve to 3 different addresses (only last one has backing stub server):
15091529 setupFakeHostNameResolution ( driver , '127.0.0.1:9010' , [ '127.0.0.1:9011' , '127.0.0.1:9012' , '127.0.0.1:9009' ] ) ;
15101530 const session = driver . session ( ) ;
15111531
1512- // start new router on a different port to emulate host name resolution
1513- // this router uses different script that contains itself as reader
1514- router1 . exit ( ( ) => {
1515- const router2 = kit . start ( './test/resources/boltkit/rediscover_using_initial_router.script' , 9009 ) ;
1516-
1517- session . readTransaction ( tx => tx . run ( 'MATCH (n) RETURN n.name AS name' ) ) . then ( result => {
1518- const records = result . records ;
1519- expect ( records . length ) . toEqual ( 2 ) ;
1520- expect ( records [ 0 ] . get ( 'name' ) ) . toEqual ( 'Bob' ) ;
1521- expect ( records [ 1 ] . get ( 'name' ) ) . toEqual ( 'Alice' ) ;
1532+ session . readTransaction ( tx => tx . run ( 'MATCH (n) RETURN n.name AS name' ) ) . then ( result => {
1533+ const records = result . records ;
1534+ expect ( records . length ) . toEqual ( 2 ) ;
1535+ expect ( records [ 0 ] . get ( 'name' ) ) . toEqual ( 'Bob' ) ;
1536+ expect ( records [ 1 ] . get ( 'name' ) ) . toEqual ( 'Alice' ) ;
15221537
1523- session . close ( ( ) => {
1524- driver . close ( ) ;
1525- router2 . exit ( code => {
1526- expect ( code ) . toEqual ( 0 ) ;
1538+ session . close ( ( ) => {
1539+ driver . close ( ) ;
1540+ router1 . exit ( code1 => {
1541+ router2 . exit ( code2 => {
1542+ expect ( code1 ) . toEqual ( 0 ) ;
1543+ expect ( code2 ) . toEqual ( 0 ) ;
15271544 done ( ) ;
15281545 } ) ;
15291546 } ) ;
0 commit comments