Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0 -> main] Increase robustness of snapshot diff python test #873

Merged
merged 6 commits into from
Mar 23, 2023
39 changes: 25 additions & 14 deletions tests/nodeos_snapshot_diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def waitForBlock(node, blockNum, blockType=BlockType.head, timeout=None, reportI
waitForBlock(node0, blockNum, blockType=BlockType.lib)

Print("Configure and launch txn generators")

targetTpsPerGenerator = 10
testTrxGenDurationSec=60*30
cluster.launchTrxGenerators(contractOwnerAcctName=cluster.eosioAccount.name, acctNamesList=[account1Name, account2Name],
Expand Down Expand Up @@ -156,12 +157,8 @@ def waitForBlock(node, blockNum, blockType=BlockType.head, timeout=None, reportI
minReqPctLeeway=0.60
minRequiredTransactions=minReqPctLeeway*transactionsPerBlock
assert steadyStateAvg>=minRequiredTransactions, "Expected to at least receive %s transactions per block, but only getting %s" % (minRequiredTransactions, steadyStateAvg)

Print("Create snapshot")
blockNumSnap=nodeSnap.getBlockNum(BlockType.head)
ret = nodeProg.scheduleSnapshotAt(blockNumSnap)
assert ret is not None, "Snapshot creation failed"

Print("Create snapshot (node 0)")
ret = nodeSnap.createSnapshot()
assert ret is not None, "Snapshot creation failed"
ret_head_block_num = ret["payload"]["head_block_num"]
Expand All @@ -178,6 +175,29 @@ def waitForBlock(node, blockNum, blockType=BlockType.head, timeout=None, reportI
Utils.processLeapUtilCmd("snapshot to-json --input-file {}".format(snapshotFile), "snapshot to-json", silentErrors=False)
snapshotFile = snapshotFile + ".json"

Print("Trim programmable blocklog to snapshot head block num and relaunch programmable node")
nodeProg.kill(signal.SIGTERM)
output=cluster.getBlockLog(progNodeId, blockLogAction=BlockLogAction.trim, first=0, last=ret_head_block_num, throwException=True)
removeState(progNodeId)
Utils.rmFromFile(Utils.getNodeConfigDir(progNodeId, "config.ini"), "p2p-peer-address")
isRelaunchSuccess = nodeProg.relaunch(chainArg="--replay", addSwapFlags={}, timeout=relaunchTimeout, cachePopen=True)
assert isRelaunchSuccess, "Failed to relaunch programmable node"

Print("Schedule snapshot (node 2)")
ret = nodeProg.scheduleSnapshotAt(ret_head_block_num)
assert ret is not None, "Snapshot scheduling failed"

Print("Wait for programmable node lib to advance")
waitForBlock(nodeProg, ret_head_block_num+1, blockType=BlockType.lib)

Print("Kill programmable node")
nodeProg.kill(signal.SIGTERM)

Print("Convert snapshot to JSON")
progSnapshotFile = getLatestSnapshot(progNodeId)
Utils.processLeapUtilCmd("snapshot to-json --input-file {}".format(progSnapshotFile), "snapshot to-json", silentErrors=False)
progSnapshotFile = progSnapshotFile + ".json"

Print("Trim irreversible blocklog to snapshot head block num")
nodeIrr.kill(signal.SIGTERM)
output=cluster.getBlockLog(irrNodeId, blockLogAction=BlockLogAction.trim, first=0, last=ret_head_block_num, throwException=True)
Expand Down Expand Up @@ -205,15 +225,6 @@ def waitForBlock(node, blockNum, blockType=BlockType.head, timeout=None, reportI
irrSnapshotFile = irrSnapshotFile + ".json"

assert Utils.compareFiles(snapshotFile, irrSnapshotFile), f"Snapshot files differ {snapshotFile} != {irrSnapshotFile}"

Print("Kill programmable node")
nodeProg.kill(signal.SIGTERM)

Print("Convert snapshot to JSON")
progSnapshotFile = getLatestSnapshot(progNodeId)
Utils.processLeapUtilCmd("snapshot to-json --input-file {}".format(progSnapshotFile), "snapshot to-json", silentErrors=False)
progSnapshotFile = progSnapshotFile + ".json"

assert Utils.compareFiles(progSnapshotFile, irrSnapshotFile), f"Snapshot files differ {progSnapshotFile} != {irrSnapshotFile}"

testSuccessful=True
Expand Down