Skip to content

Commit be73a68

Browse files
authored
Merge pull request #1179 from AntelopeIO/merge_lib_advance_test_fix
[1.1.0 -> main] Test: Determine the failure of lib_advance_test using the number of unique unlinkable blocks
2 parents eb23777 + 684ea3e commit be73a68

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

tests/TestHarness/Node.py

+24
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,30 @@ def verifyUnlinkableBlocksExpected(self, syncFetchSpan) -> bool:
731731
else:
732732
return True
733733

734+
# Returns the number of unique unlinkable blocks in stderr.txt.
735+
def numUniqueUnlinkableBlocks(self) -> int:
736+
dataDir = Utils.getNodeDataDir(self.nodeId)
737+
logFile = dataDir + "/stderr.txt"
738+
739+
pattern = re.compile(r"unlinkable_block\s(\d+)")
740+
741+
# Use set for uniqueness, as the same block can be unlinkable multiple
742+
# times due to multiple connections.
743+
uniqueBlocks = set()
744+
with open(logFile, 'r') as f:
745+
for line in f:
746+
match = pattern.search(line)
747+
if match:
748+
try:
749+
blockNum = int(match.group(1))
750+
uniqueBlocks.add(blockNum)
751+
except ValueError:
752+
Utils.Print(f"unlinkable block number cannot be converted into integer: in {line.strip()} of {f}")
753+
assert(False) # Cannot happen. Fail the test.
754+
numUnlinkableBlocks = len(uniqueBlocks)
755+
Utils.Print(f"Number of unique unlinkable blocks: {numUnlinkableBlocks}")
756+
return numUnlinkableBlocks
757+
734758
# Verify that we have only one "Starting block" in the log for any block number unless:
735759
# - the block was restarted because it was exhausted,
736760
# - or the second "Starting block" is for a different block time than the first.

tests/lib_advance_test.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@
143143

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

152150
testSuccessful=True
153151
finally:

0 commit comments

Comments
 (0)