Skip to content

Commit

Permalink
Fix sync_ban.py (#10323)
Browse files Browse the repository at this point in the history
The log message tracked by this test was changed.
  • Loading branch information
VanBarbascu authored Dec 12, 2023
1 parent 4f811e7 commit e5d808b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions chain/client/src/sync/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl HeaderSync {
if now > *stalling_ts + self.stall_ban_timeout
&& *highest_height == peer.highest_block_height
{
// This message is used in sync_ban.py test. Consider checking there as well if you change it.
// The peer is one of the peers with the highest height, but we consider the peer stalling.
warn!(target: "sync", "Sync: ban a peer: {}, for not providing enough headers. Peer's height: {}", peer.peer_info, peer.highest_block_height);
// Ban the peer, which blocks all interactions with the peer for some time.
Expand Down
4 changes: 4 additions & 0 deletions pytest/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def check(self, pattern: str) -> bool:
"""Check whether the pattern can be found in the logs."""
return pattern in self._read_file()

def check_re(self, pattern: str) -> bool:
"""Check whether the regex pattern can be found in the logs."""
return re.search(pattern, self._read_file()) != None

def reset(self) -> None:
"""Resets log offset to beginning of the file."""
self.offset = 0
Expand Down
8 changes: 4 additions & 4 deletions pytest/tests/sanity/sync_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
TIMEOUT = 300
EPOCH_LENGTH = 50

BAN_STRING = 'ban a fraudulent peer'
BAN_STRING = 'ban a peer: [^\n]*, for not providing enough headers'


class Handler(ProxyHandler):
Expand Down Expand Up @@ -108,7 +108,7 @@ async def handle(self, msg, fr, to):
assert time.time() - start < TIMEOUT

if should_ban:
if tracker1.check(BAN_STRING):
if tracker1.check_re(BAN_STRING):
break
else:
cur_height = nodes[0].get_latest_block().height
Expand All @@ -122,8 +122,8 @@ async def handle(self, msg, fr, to):
break
time.sleep(2)

if not should_ban and (tracker0.check(BAN_STRING) or
tracker1.check(BAN_STRING)):
if not should_ban and (tracker0.check_re(BAN_STRING) or
tracker1.check_re(BAN_STRING)):
assert False, "unexpected ban of peers"

# logger.info('shutting down')
Expand Down

0 comments on commit e5d808b

Please sign in to comment.