From 3bc9cffdb85ec9009827216c3401d0048083da33 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 18 Feb 2025 09:58:41 -0500 Subject: [PATCH] Determine the failure of lib_advance_test using the number of unique unlinkable blocks --- tests/TestHarness/Node.py | 24 ++++++++++++++++++++++++ tests/lib_advance_test.py | 8 +++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/TestHarness/Node.py b/tests/TestHarness/Node.py index 0511899723..f854131330 100644 --- a/tests/TestHarness/Node.py +++ b/tests/TestHarness/Node.py @@ -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. diff --git a/tests/lib_advance_test.py b/tests/lib_advance_test.py index 44d9c67c35..e75b78e59d 100755 --- a/tests/lib_advance_test.py +++ b/tests/lib_advance_test.py @@ -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: