test: Prefer send_and_ping over send_message+sync_with_ping

Also, add an explanation for the preference in the docs.
This commit is contained in:
MarcoFalke
2025-02-13 16:14:01 +01:00
parent 698f86964c
commit fa4356717d
3 changed files with 14 additions and 16 deletions

View File

@ -382,7 +382,13 @@ class P2PConnection(asyncio.Protocol):
"""Send a P2P message over the socket.
This method takes a P2P payload, builds the P2P header and adds
the message to the send buffer to be sent over the socket."""
the message to the send buffer to be sent over the socket.
When a message does not lead to a disconnect, send_and_ping is usually
preferred to send a message. This can help to reduce intermittent test
failures due to a missing sync. Also, it includes a call to
sync_with_ping, allowing for concise test code.
"""
with self._send_lock:
tmsg = self.build_message(message, is_decoy)
self._log_message("send", message)