aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2020-01-16 17:44:29 +0800
committerfanquake <fanquake@gmail.com>2020-01-16 17:57:29 +0800
commit4e8b564df0d4ff2bc2463aa072b15471361d9e7d (patch)
tree8c5f6a53a0474395900dc8cfc02712ad3ee9de4e
parentac61ec9da6793f00b29ba11f784b9b1c3ae662e9 (diff)
parentf117fb00da747147cddfb071c1427a2754c278cd (diff)
Merge #17931: test: Fix p2p_invalid_messages failing in Python 3.8 because of warning
f117fb00da747147cddfb071c1427a2754c278cd Replace coroutine with async def in p2p_invalid_messages.py (Elichai Turkel) Pull request description: In Python 3.8 `p2p_invalid_messages.py` fails because of the following warning python produce: ``` 2020-01-15T13:02:14.486000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_3xq0f6uh ./test/functional/p2p_invalid_messages.py:154: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead asyncio.run_coroutine_threadsafe(asyncio.coroutine(swap_magic_bytes)(), NetworkThread.network_event_loop).result() 2020-01-15T13:02:15.306000Z TestFramework (INFO): Sending a bunch of large, junk messages to test memory exhaustion. May take a bit... 2020-01-15T13:02:17.971000Z TestFramework (INFO): Waiting for node to drop junk messages. 2020-01-15T13:02:18.042000Z TestFramework.mininode (WARNING): Connection lost to 127.0.0.1:12826 due to [Errno 104] Connection reset by peer 2020-01-15T13:02:18.141000Z TestFramework (INFO): Sending a message with incorrect size of 2 2020-01-15T13:02:18.293000Z TestFramework (INFO): Sending a message with incorrect size of 77 2020-01-15T13:02:18.344000Z TestFramework.mininode (WARNING): Connection lost to 127.0.0.1:12826 due to [Errno 104] Connection reset by peer 2020-01-15T13:02:18.445000Z TestFramework (INFO): Sending a message with incorrect size of 78 2020-01-15T13:02:18.597000Z TestFramework (INFO): Sending a message with incorrect size of 79 2020-01-15T13:02:18.902000Z TestFramework (INFO): Stopping nodes 2020-01-15T13:02:19.154000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_3xq0f6uh on exit 2020-01-15T13:02:19.154000Z TestFramework (INFO): Tests successful ``` so as it says I replaced the co-routine with `async def` which IIUC is supported since Python 3.5, so this makes the test pass both on 3.5+ and on 3.8 https://docs.python.org/3.5/library/asyncio-task.html ("The async def type of coroutine was added in Python 3.5, and is recommended if there is no need to support older Python versions") ACKs for top commit: laanwj: ACK f117fb00da747147cddfb071c1427a2754c278cd if it passes travis fanquake: ACK f117fb00da747147cddfb071c1427a2754c278cd - observed the failure (it's the only test that fails) with Python 3.8.1, tested the fix with 3.5.6 and 3.8.1. This is our only usage of `asyncio.coroutine`. Tree-SHA512: c21d50b23ef4d8a777fd1d9dfe433c85b0b5fff35afbd338817021ffcd42caea64b4c70e46cb3a8a543a1bf2aaa9a6b4f075f6493ab64192bc12bf8bafc54a87
-rwxr-xr-xtest/functional/p2p_invalid_messages.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py
index 20864881c1..07eacf410d 100755
--- a/test/functional/p2p_invalid_messages.py
+++ b/test/functional/p2p_invalid_messages.py
@@ -145,13 +145,13 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_magic_bytes(self):
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
- def swap_magic_bytes():
+ async def swap_magic_bytes():
conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes
conn.magic_bytes = b'\x00\x11\x22\x32'
# Call .result() to block until the atomic swap is complete, otherwise
# we might run into races later on
- asyncio.run_coroutine_threadsafe(asyncio.coroutine(swap_magic_bytes)(), NetworkThread.network_event_loop).result()
+ asyncio.run_coroutine_threadsafe(swap_magic_bytes(), NetworkThread.network_event_loop).result()
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']):
conn.send_message(messages.msg_ping(nonce=0xff))