Skip to content

Commit

Permalink
Do not arbitrarily sleep when waiting for all messages
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Mar 21, 2024
1 parent 8ab5239 commit f34ab07
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/functional/p2p_invalid_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from test_framework.util import (
assert_equal,
hex_str_to_bytes,
wait_until,
)
from random import getrandbits

Expand Down Expand Up @@ -55,6 +56,10 @@ def on_getdata(self, message):
self.send_message(self.vec_mnp[inv.hash])
self.getdata_count+=1

def wait_for_p2p_messages(self, n_messages):
wait_until(lambda: self.getdata_count == n_messages, timeout=60)


class InvalidMessagesTest(PivxTestFramework):
def set_test_params(self):
self.num_nodes = 1
Expand Down Expand Up @@ -217,18 +222,14 @@ def test_fill_askfor(self):
assert_equal(len(invs), 50000)
msg = messages.msg_inv(invs)
conn.send_message(msg)

time.sleep(30) # wait a bit
assert_equal(conn.getdata_count, 50000)
conn.wait_for_p2p_messages(50000)

# Prior #2611 the node was blocking any follow-up request.
mnp = msg_mnping(CTxIn(COutPoint(getrandbits(256))), getrandbits(256), int(time.time()))
conn.vec_mnp[mnp.get_hash()] = mnp
msg = messages.msg_inv([messages.CInv(15, mnp.get_hash())])
conn.send_and_ping(msg)
time.sleep(3)

assert_equal(conn.getdata_count, 50001)
conn.wait_for_p2p_messages(50001)
self.nodes[0].disconnect_p2ps()

def test_resource_exhaustion(self):
Expand Down

0 comments on commit f34ab07

Please sign in to comment.