@@ -1523,7 +1523,7 @@ def test_should_pass_bookmark_from_tx_to_tx_using_tx_run(self):
15231523 self .assertEqual (["BookmarkB" ], first_bookmark )
15241524 self .assertEqual (["BookmarkC" ], second_bookmark )
15251525
1526- def test_should_retry_read_tx_until_success (self ):
1526+ def test_should_retry_read_tx_until_success_on_error (self ):
15271527 # TODO remove this block once all languages work
15281528 if get_driver_name () in ['dotnet' ]:
15291529 self .skipTest ("requires investigation" )
@@ -1576,7 +1576,59 @@ def work(tx):
15761576 self .assertEqual ([[1 ]], sequences )
15771577 self .assertEqual (2 , try_count )
15781578
1579- def test_should_retry_write_tx_until_success (self ):
1579+ def test_should_retry_read_tx_until_success_on_no_connection (self ):
1580+ driver = Driver (self ._backend , self ._uri_with_context , self ._auth ,
1581+ self ._userAgent )
1582+ self ._routingServer1 .start (script = self .router_script_adb (),
1583+ vars = self .get_vars ())
1584+ self ._readServer1 .start (
1585+ script = self .read_tx_script (),
1586+ vars = self .get_vars ()
1587+ )
1588+ self ._readServer2 .start (
1589+ script = self .read_tx_script (),
1590+ vars = self .get_vars ()
1591+ )
1592+
1593+ session = driver .session ('r' , database = self .get_db ())
1594+ sequences = []
1595+ try_count = 0
1596+
1597+ def work (tx ):
1598+ nonlocal try_count
1599+ try_count = try_count + 1
1600+ result = tx .run ("RETURN 1 as n" )
1601+ sequences .append (self .collectRecords (result ))
1602+
1603+ session .readTransaction (work )
1604+ self ._routingServer1 .done ()
1605+ connection_counts = (
1606+ self ._readServer1 .count_responses ("<ACCEPT>" ),
1607+ self ._readServer2 .count_responses ("<ACCEPT>" )
1608+ )
1609+ self .assertIn (connection_counts , {(0 , 1 ), (1 , 0 )})
1610+ if connection_counts == (1 , 0 ):
1611+ self ._readServer1 .done ()
1612+ else :
1613+ self ._readServer2 .done ()
1614+ self .assertEqual ([[1 ]], sequences )
1615+ self .assertEqual (1 , try_count )
1616+
1617+ session .readTransaction (work )
1618+ session .close ()
1619+ driver .close ()
1620+
1621+ self ._readServer1 .done ()
1622+ self ._readServer2 .done ()
1623+ self .assertEqual ([[1 ], [1 ]], sequences )
1624+ # Drivers might or might not try the first server again
1625+ self .assertLessEqual (try_count , 3 )
1626+ # TODO: Design a test that makes sure the driver doesn't run the tx func
1627+ # if it can't establish a working connection to the server. So
1628+ # that `try_count == 2`. When doing so be aware that drivers could
1629+ # do round robin, e.g. Java.
1630+
1631+ def test_should_retry_write_tx_until_success_on_error (self ):
15801632 # TODO remove this block once all languages work
15811633 if get_driver_name () in ['dotnet' ]:
15821634 self .skipTest ("requires investigation" )
@@ -1629,6 +1681,58 @@ def work(tx):
16291681 self .assertEqual ([[]], sequences )
16301682 self .assertEqual (2 , try_count )
16311683
1684+ def test_should_retry_write_tx_until_success_on_no_connection (self ):
1685+ driver = Driver (self ._backend , self ._uri_with_context , self ._auth ,
1686+ self ._userAgent )
1687+ self ._routingServer1 .start (script = self .router_script_adb (),
1688+ vars = self .get_vars ())
1689+ self ._writeServer1 .start (
1690+ script = self .write_tx_script (),
1691+ vars = self .get_vars ()
1692+ )
1693+ self ._writeServer2 .start (
1694+ script = self .write_tx_script (),
1695+ vars = self .get_vars ()
1696+ )
1697+
1698+ session = driver .session ('r' , database = self .get_db ())
1699+ sequences = []
1700+ try_count = 0
1701+
1702+ def work (tx ):
1703+ nonlocal try_count
1704+ try_count = try_count + 1
1705+ result = tx .run ("RETURN 1 as n" )
1706+ sequences .append (self .collectRecords (result ))
1707+
1708+ session .writeTransaction (work )
1709+ self ._routingServer1 .done ()
1710+ connection_counts = (
1711+ self ._writeServer1 .count_responses ("<ACCEPT>" ),
1712+ self ._writeServer2 .count_responses ("<ACCEPT>" )
1713+ )
1714+ self .assertIn (connection_counts , {(0 , 1 ), (1 , 0 )})
1715+ if connection_counts == (1 , 0 ):
1716+ self ._writeServer1 .done ()
1717+ else :
1718+ self ._writeServer2 .done ()
1719+ self .assertEqual ([[]], sequences )
1720+ self .assertEqual (1 , try_count )
1721+
1722+ session .writeTransaction (work )
1723+ session .close ()
1724+ driver .close ()
1725+
1726+ self ._writeServer1 .done ()
1727+ self ._writeServer2 .done ()
1728+ self .assertEqual ([[], []], sequences )
1729+ # Drivers might or might not try the first server again
1730+ self .assertLessEqual (try_count , 3 )
1731+ # TODO: Design a test that makes sure the driver doesn't run the tx func
1732+ # if it can't establish a working connection to the server. So
1733+ # that `try_count == 2`. When doing so be aware that drivers could
1734+ # do round robin, e.g. Java.
1735+
16321736 def test_should_retry_read_tx_and_rediscovery_until_success (self ):
16331737 # TODO remove this block once all languages work
16341738 if get_driver_name () in ['dotnet' , 'go' ]:
0 commit comments