4
4
import infra .network
5
5
import infra .proc
6
6
import time
7
+ import http
8
+ from ccf .tx_status import TxStatus
7
9
8
10
from loguru import logger as LOG
9
11
10
12
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
+
11
36
def run (args ):
12
37
hosts = ["localhost" ] * 5
13
38
@@ -25,13 +50,14 @@ def run(args):
25
50
txs = []
26
51
# Run some transactions that can't be committed
27
52
with primary .client ("user0" ) as uc :
28
- for i in range (10 ):
53
+ for i in range (3 ):
29
54
txs .append (
30
55
uc .post ("/app/log/private" , {"id" : 100 + i , "msg" : "Hello world" })
31
56
)
32
57
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 )
35
61
36
62
# Kill the primary, restore other backups
37
63
primary .stop ()
@@ -41,7 +67,6 @@ def run(args):
41
67
primary .node_id , timeout_multiplier = 6
42
68
)
43
69
LOG .debug (f"New primary is { new_primary .node_id } in term { new_term } " )
44
- assert new_primary .node_id == backups [0 ].node_id
45
70
46
71
# Check that uncommitted but committable suffix is preserved
47
72
with new_primary .client ("user0" ) as uc :
0 commit comments