44import infra .network
55import infra .proc
66import time
7+ import http
8+ from ccf .tx_status import TxStatus
79
810from loguru import logger as LOG
911
1012
13+ def wait_for_pending (client , view , seqno , timeout = 3 ):
14+ end_time = time .time () + timeout
15+ while time .time () < end_time :
16+ r = client .get (f"/node/tx?view={ view } &seqno={ seqno } " )
17+ assert (
18+ r .status_code == http .HTTPStatus .OK
19+ ), f"tx request returned HTTP status { r .status_code } "
20+ status = TxStatus (r .body .json ()["status" ])
21+ if status == TxStatus .Pending :
22+ return
23+ elif status == TxStatus .Invalid :
24+ raise RuntimeError (
25+ f"Transaction ID { view } .{ seqno } is marked invalid and will never be committed"
26+ )
27+ elif status == TxStatus .Committed :
28+ raise RuntimeError (
29+ f"Transaction ID { view } .{ seqno } is unexpectedly marked committed"
30+ )
31+ else :
32+ time .sleep (0.1 )
33+ raise TimeoutError ("Timed out waiting for commit" )
34+
35+
1136def run (args ):
1237 hosts = ["localhost" ] * 5
1338
@@ -25,13 +50,14 @@ def run(args):
2550 txs = []
2651 # Run some transactions that can't be committed
2752 with primary .client ("user0" ) as uc :
28- for i in range (10 ):
53+ for i in range (3 ):
2954 txs .append (
3055 uc .post ("/app/log/private" , {"id" : 100 + i , "msg" : "Hello world" })
3156 )
3257
33- # Wait for a signature to ensure those transactions are committable
34- time .sleep (args .sig_tx_interval * 2 / 1000 )
58+ sig_view , sig_seqno = txs [- 1 ].view , txs [- 1 ].seqno + 1
59+ with backups [0 ].client () as bc :
60+ wait_for_pending (bc , sig_view , sig_seqno )
3561
3662 # Kill the primary, restore other backups
3763 primary .stop ()
@@ -41,7 +67,6 @@ def run(args):
4167 primary .node_id , timeout_multiplier = 6
4268 )
4369 LOG .debug (f"New primary is { new_primary .node_id } in term { new_term } " )
44- assert new_primary .node_id == backups [0 ].node_id
4570
4671 # Check that uncommitted but committable suffix is preserved
4772 with new_primary .client ("user0" ) as uc :
0 commit comments