@@ -1466,27 +1466,44 @@ describe('routing driver', () => {
1466
1466
}
1467
1467
1468
1468
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 ) ;
1470
1472
1471
1473
kit . run ( ( ) => {
1472
1474
const driver = newDriver ( 'bolt+routing://127.0.0.1:9010' ) ;
1473
- const session = driver . session ( ) ;
1474
1475
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 ) ;
1484
1487
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
+ } ) ;
1490
1507
} ) ;
1491
1508
} ) ;
1492
1509
} ) ;
@@ -1502,28 +1519,28 @@ describe('routing driver', () => {
1502
1519
1503
1520
const kit = new boltkit . BoltKit ( ) ;
1504
1521
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 ) ;
1505
1525
1506
1526
kit . run ( ( ) => {
1507
1527
const driver = newDriver ( 'bolt+routing://127.0.0.1:9010' ) ;
1508
1528
// make seed address resolve to 3 different addresses (only last one has backing stub server):
1509
1529
setupFakeHostNameResolution ( driver , '127.0.0.1:9010' , [ '127.0.0.1:9011' , '127.0.0.1:9012' , '127.0.0.1:9009' ] ) ;
1510
1530
const session = driver . session ( ) ;
1511
1531
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' ) ;
1522
1537
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 ) ;
1527
1544
done ( ) ;
1528
1545
} ) ;
1529
1546
} ) ;
0 commit comments