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

[1.1.0] Test: Determine the failure of lib_advance_test using the number of unique unlinkable blocks #1174

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/TestHarness/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,30 @@ def verifyUnlinkableBlocksExpected(self, syncFetchSpan) -> bool:
else:
return True

# Returns the number of unique unlinkable blocks in stderr.txt.
def numUniqueUnlinkableBlocks(self) -> int:
dataDir = Utils.getNodeDataDir(self.nodeId)
logFile = dataDir + "/stderr.txt"

pattern = re.compile(r"unlinkable_block\s(\d+)")

# Use set for uniqueness, as the same block can be unlinkable multiple
# times due to multiple connections.
uniqueBlocks = set()
with open(logFile, 'r') as f:
for line in f:
match = pattern.search(line)
if match:
try:
blockNum = int(match.group(1))
uniqueBlocks.add(blockNum)
except ValueError:
Utils.Print(f"unlinkable block number cannot be converted into integer: in {line.strip()} of {f}")
assert(False) # Cannot happen. Fail the test.
numUnlinkableBlocks = len(uniqueBlocks)
Utils.Print(f"Number of unique unlinkable blocks: {numUnlinkableBlocks}")
return numUnlinkableBlocks

# Verify that we have only one "Starting block" in the log for any block number unless:
# - the block was restarted because it was exhausted,
# - or the second "Starting block" is for a different block time than the first.
Expand Down
8 changes: 3 additions & 5 deletions tests/lib_advance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@

# instant finality does not drop late blocks, but can still get unlinkable when syncing and getting a produced block
allowedUnlinkableBlocks = afterBlockNum-beforeBlockNum
logFile = Utils.getNodeDataDir(prodNode3.nodeId) + "/stderr.txt"
f = open(logFile)
contents = f.read()
if contents.count("unlinkable_block") > (allowedUnlinkableBlocks):
errorExit(f"Node{prodNode3.nodeId} has more than {allowedUnlinkableBlocks} unlinkable blocks: {logFile}.")
numUnlinkableBlocks = prodNode3.numUniqueUnlinkableBlocks()
if numUnlinkableBlocks > allowedUnlinkableBlocks:
errorExit(f"Node{prodNode3.nodeId} has {numUnlinkableBlocks} unlinkable blocks which is more than allowed {allowedUnlinkableBlocks}.")

testSuccessful=True
finally:
Expand Down