Skip to content

Commit dd5cf38

Browse files
committed
test: check for specific disconnect reasons in feature_maxuploadtarget.py
This ensures that the disconnect happens for the expected reason and also makes it easier to navigate between implementation and test code, i.e. both the questions "do we have test coverage for this disconnect?" (from an implementation reader's perspective) and "where is the code handling this disconnect?" (from a test reader's perspective) can be answered simply by grep-ping the corresponding debug message.
1 parent 73d7372 commit dd5cf38

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

test/functional/feature_maxuploadtarget.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def run_test(self):
119119
assert_equal(len(self.nodes[0].getpeerinfo()), 3)
120120
# At most a couple more tries should succeed (depending on how long
121121
# the test has been running so far).
122-
for _ in range(3):
123-
p2p_conns[0].send_message(getdata_request)
124-
p2p_conns[0].wait_for_disconnect()
122+
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnect peer"]):
123+
for _ in range(3):
124+
p2p_conns[0].send_message(getdata_request)
125+
p2p_conns[0].wait_for_disconnect()
125126
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
126127
self.log.info("Peer 0 disconnected after downloading old block too many times")
127128

@@ -143,8 +144,9 @@ def run_test(self):
143144

144145
# But if p2p_conns[1] tries for an old block, it gets disconnected too.
145146
getdata_request.inv = [CInv(MSG_BLOCK, big_old_block)]
146-
p2p_conns[1].send_message(getdata_request)
147-
p2p_conns[1].wait_for_disconnect()
147+
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnect peer"]):
148+
p2p_conns[1].send_message(getdata_request)
149+
p2p_conns[1].wait_for_disconnect()
148150
assert_equal(len(self.nodes[0].getpeerinfo()), 1)
149151

150152
self.log.info("Peer 1 disconnected after trying to download old block")

0 commit comments

Comments
 (0)