Skip to content

Commit

Permalink
GH-2125 Improve test robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 9, 2024
1 parent 5d9faff commit 00d8ccf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/lib_advance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
prodNodes=[ prodNode0, prodNode1, prodNode2, prodNode3 ]

prodA=prodNode0 # defproducera
prodD=prodNode3 # defproducerc
prodD=prodNode3 # defproducerd

# *** Identify a block where production is stable ***

Expand Down
16 changes: 16 additions & 0 deletions tests/trx_finality_status_forked_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def getState(status):
if state == forkedOutState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > transBlockNum ):
break

if state == irreversibleState:
Print(f"Transaction became irreversible before it could be found forked out: {json.dumps(retStatus, indent=1)}")
sys.exit(0)

assert state == forkedOutState, \
f"ERROR: getTransactionStatus didn't return \"{forkedOutState}\" state.\n\nstatus: {json.dumps(retStatus, indent=1)}" + \
f"\n\nprod A info: {json.dumps(prodA.getInfo(), indent=1)}\n\nprod D info: {json.dumps(prodD.getInfo(), indent=1)}"
Expand All @@ -182,6 +186,18 @@ def getState(status):
retStatus = prodD.getTransactionStatus(transId)
state = getState(retStatus)

# it is possible for another fork switch to cause the trx to be forked out again
if state == forkedOutState:
while True:
info = prodD.getInfo()
retStatus = prodD.getTransactionStatus(transId)
state = getState(retStatus)
if state == localState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > retBlockNum ):
continue
retBlockNum = retStatus["block_number"]
if (state == inBlockState or state == irreversibleState) or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > retBlockNum ):
break

assert state == inBlockState or state == irreversibleState, \
f"ERROR: getTransactionStatus didn't return \"{inBlockState}\" or \"{irreversibleState}\" state.\n\nstatus: {json.dumps(retStatus, indent=1)}" + \
f"\n\nprod A info: {json.dumps(prodA.getInfo(), indent=1)}\n\nprod D info: {json.dumps(prodD.getInfo(), indent=1)}"
Expand Down

0 comments on commit 00d8ccf

Please sign in to comment.