One of the `p2p_invalid_messages.py` tests is race-condition-ey. I propose a fix here.
This came up when reviewing !1464 (merged), see MR comment here: !1464 (comment 821616428)
The test is trying to send 1/2 of a full p2p message, wait a bit, then send the other half sometime later, and be sure the node did correctly receive it, even if in 2 parts, and did correctly process it.
While the test is a good idea, the technique used, which is to simply poll getnettotals
for byte counts, to be sure the node received the message, is flawed, because, even as the test author points out, it can fail spuriously anyway if the node received a bunch of messages from the test framework itself in-between.
A better test would be:
- Compose an INV message with a fake random hash.
- Send part of that message
- Wait a little bit (like milliseconds)
- Send the remaining part, but do a
with debug_log
scanning that the node got the INV with the hash we sent (regtest nodes in the test framework log all the INVs they see).
The change proposed above would mean that section of p2p_invalid_messages.py
would never fail due to race conditions.