Skip to content

Commit 90bbc58

Browse files
authored
Make committable test more robust (#1684)
1 parent 3df0069 commit 90bbc58

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ if(BUILD_TESTS)
640640
NAME committable_suffix_test
641641
PYTHON_SCRIPT ${CMAKE_SOURCE_DIR}/tests/committable.py
642642
CONSENSUS cft
643-
ADDITIONAL_ARGS --raft-election-timeout 4000
643+
ADDITIONAL_ARGS --raft-election-timeout 4000 --sig-ms-interval 100
644644
)
645645

646646
add_e2e_test(

tests/committable.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,35 @@
44
import infra.network
55
import infra.proc
66
import time
7+
import http
8+
from ccf.tx_status import TxStatus
79

810
from 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+
1136
def 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

Comments
 (0)