Skip to content

Conversation

elichai
Copy link
Contributor

@elichai elichai commented Jan 15, 2020

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")

@fanquake fanquake added the Tests label Jan 15, 2020
@laanwj
Copy link
Member

laanwj commented Jan 15, 2020

I think it's somewhat strange for the test to fail on a warning, but I also think this change makes sense.

ACK f117fb0 if it passes travis

@elichai
Copy link
Contributor Author

elichai commented Jan 15, 2020

I think currently the tests fail if the python side prints anything to stdout/stderr

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f117fb0 - 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.

72/136 - p2p_invalid_messages.py failed, Duration: 9 s

stdout:
2020-01-16T09:37:44.223000Z TestFramework (INFO): Initializing test directory /var/folders/z2/cn877pxd3czdfh47mfkmbwgm0000gn/T/test_runner_₿_🏃_20200116_173347/p2p_invalid_messages_62
2020-01-16T09:37:46.045000Z TestFramework (INFO): Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...
2020-01-16T09:37:51.293000Z TestFramework (INFO): Waiting for node to drop junk messages.
2020-01-16T09:37:51.344000Z TestFramework (INFO): Skipping test p2p_invalid_messages/1 (oversized message) under macOS
2020-01-16T09:37:51.348000Z TestFramework (INFO): Sending a message with incorrect size of 2
2020-01-16T09:37:51.413000Z TestFramework.mininode (WARNING): Connection lost to 127.0.0.1:11744 due to [Errno 54] Connection reset by peer
2020-01-16T09:37:51.525000Z TestFramework (INFO): Sending a message with incorrect size of 77
2020-01-16T09:37:51.585000Z TestFramework.mininode (WARNING): Connection lost to 127.0.0.1:11744 due to [Errno 54] Connection reset by peer
2020-01-16T09:37:51.692000Z TestFramework (INFO): Sending a message with incorrect size of 78
2020-01-16T09:37:51.880000Z TestFramework (INFO): Sending a message with incorrect size of 79
2020-01-16T09:37:52.212000Z TestFramework (INFO): Stopping nodes
2020-01-16T09:37:52.691000Z TestFramework (INFO): Cleaning up /var/folders/z2/cn877pxd3czdfh47mfkmbwgm0000gn/T/test_runner_₿_🏃_20200116_173347/p2p_invalid_messages_62 on exit
2020-01-16T09:37:52.691000Z TestFramework (INFO): Tests successful


stderr:
/Users/michael/github/bitcoin/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()

fanquake added a commit that referenced this pull request Jan 16, 2020
…cause of warning

f117fb0 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 f117fb0 if it passes travis
  fanquake:
    ACK f117fb0 - 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
@fanquake fanquake merged commit f117fb0 into bitcoin:master Jan 16, 2020
@elichai elichai deleted the 2020-01-coroutine branch January 16, 2020 10:04
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 7, 2020
- doc: fix git add argument bitcoin#18513
- build: Fix libevent linking for bench_bitcoin binary bitcoin#18397
- script: fix SCRIPT_ERR_SIG_PUSHONLY error string bitcoin#18412
- doc: Comment fix merkle.cpp bitcoin#18379
- log: Fix UB with bench on genesis block bitcoin#15283
- test: Fix mining to an invalid target + ensure that a new block has the correct hash internally bitcoin#18350
- Fix missing header in sync.h bitcoin#18357
- refactor: Fix implicit value conversion in formatPingTime bitcoin#18260
- Fix .gitignore policy in build_msvc directory bitcoin#18108
- build: Fix behavior when ALLOW_HOST_PACKAGES unset bitcoin#18051
- test: Fix p2p_invalid_messages failing in Python 3.8 because of warning bitcoin#17931
- qa: Fix double-negative arg test bitcoin#17893
- build: Fix configure report about qr bitcoin#17547
- log: Fix log message for -par=1 bitcoin#17325
- bench: Fix negative values and zero for -evals flag bitcoin#17267
- depends: fix boost mac cross build with clang 9+ bitcoin#17231
- doc: Fix broken bitcoin-cli examples bitcoin#17119
- doc: fix Makefile target in benchmarking.md bitcoin#17081
- contrib: fix minor typos in makeseeds.py bitcoin#17042
- test: Fix Python Docstring to include all Args. bitcoin#17030
- doc: Fix some misspellings bitcoin#17351
- doc: Doxygen-friendly script/descriptor.h comments bitcoin#16947
- doc: Fix doxygen errors bitcoin#17945
- doc: Doxygen-friendly CuckooCache comments bitcoin#16986
- doc: Add to Doxygen documentation guidelines bitcoin#17873
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 7, 2020
- doc: fix git add argument bitcoin#18513
- build: Fix libevent linking for bench_bitcoin binary bitcoin#18397
- script: fix SCRIPT_ERR_SIG_PUSHONLY error string bitcoin#18412
- doc: Comment fix merkle.cpp bitcoin#18379
- log: Fix UB with bench on genesis block bitcoin#15283
- test: Fix mining to an invalid target + ensure that a new block has the correct hash internally bitcoin#18350
- Fix missing header in sync.h bitcoin#18357
- refactor: Fix implicit value conversion in formatPingTime bitcoin#18260
- Fix .gitignore policy in build_msvc directory bitcoin#18108
- build: Fix behavior when ALLOW_HOST_PACKAGES unset bitcoin#18051
- test: Fix p2p_invalid_messages failing in Python 3.8 because of warning bitcoin#17931
- qa: Fix double-negative arg test bitcoin#17893
- build: Fix configure report about qr bitcoin#17547
- log: Fix log message for -par=1 bitcoin#17325
- bench: Fix negative values and zero for -evals flag bitcoin#17267
- depends: fix boost mac cross build with clang 9+ bitcoin#17231
- doc: Fix broken bitcoin-cli examples bitcoin#17119
- doc: fix Makefile target in benchmarking.md bitcoin#17081
- contrib: fix minor typos in makeseeds.py bitcoin#17042
- test: Fix Python Docstring to include all Args. bitcoin#17030
- doc: Fix some misspellings bitcoin#17351
- doc: Doxygen-friendly script/descriptor.h comments bitcoin#16947
- doc: Fix doxygen errors bitcoin#17945
- doc: Doxygen-friendly CuckooCache comments bitcoin#16986
- doc: Add to Doxygen documentation guidelines bitcoin#17873
- depends: Consistent use of package variable bitcoin#17928
- init: Replace URL_WEBSITE with PACKAGE_URL bitcoin#18503
- doc: Add missed copyright headers bitcoin#17691
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 8, 2020
…cause of warning

Summary:
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

Backport of Core [[bitcoin/bitcoin#17931 | PR17931]]

This fixes an issue that @deadalnix experienced where Python 3.8+ fails on this test.

Test Plan:
```
test_runner.py p2p_invalid_messages
```

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6462
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Apr 14, 2021
…cause of warning

Summary:
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

Backport of Core [[bitcoin/bitcoin#17931 | PR17931]]

This fixes an issue that @deadalnix experienced where Python 3.8+ fails on this test.

Test Plan:
```
test_runner.py p2p_invalid_messages
```

Differential Revision: https://reviews.bitcoinabc.org/D6462
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jun 28, 2021
…t framework update)

7b04c0a [Test] Clean duplicate connections creation in mining_pos_coldStaking.py (furszy)
15a799e [Test] MAX_PROTOCOL_MESSAGE_LENGTH PIVXified. (furszy)
0aedf35 [tests] Don't import asyncio to test magic bytes (John Newbery)
9bb5309 Refactor resource exhaustion test (Troy Giorshev)
589a780 Fix "invalid message size" test (Troy Giorshev)
8a0c12b Move size limits to module-global (Troy Giorshev)
b3391c5 Remove two unneeded tests (Troy Giorshev)
1404e68 test: Add various low-level p2p tests (furszy)
8aaf7e1 test: Remove fragile assert_memory_usage_stable (MarcoFalke)
f68e22c [Test] p2p_invalid_messages.py do not change msg.command in test_command and raise sync_with_ping timeout (furszy)
c851c0b Test framework: Wait for verack by default on every new connection (furszy)
c02e9a0 [Test] move framework subversion to string (furszy)
3472a39 Replace coroutine with async def in p2p_invalid_messages.py (Elichai Turkel)
33c7b19 net_processing: align msg checksum check properly. (furszy)
7f71b1b Hash P2P messages as they are received instead of at process-time (furszy)
215a638 test: Skip flaky p2p_invalid_messages test on macOS (Fabian Jahr)
c11f565 qa: Make swap_magic_bytes in p2p_invalid_messages atomic (MarcoFalke)
be979ad test: Fix race in p2p_invalid_messages (MarcoFalke)
6a72f0c qa: Add tests for invalid message headers (MarcoFalke)
51ddd3d Introduce p2p_invalid_messages.py test (furszy)
55a37b5 net: fix missing jump line in "Oversized message from peer.." error. (furszy)
0edfce5 test_node: get_mem_rss fixups (MarcoFalke)
6f21213 tests: add P2PConnection.send_raw_message (James O'Beirne)
ae68c6e tests: add utility to assert node memory usage hasn't increased (James O'Beirne)
8469afe test: forward timeouts properly in send_blocks_and_test (James O'Beirne)
db28a53 Skip is_closing() check when not available. (Daniel Kraft)
be9dacb tests: fixes mininode's P2PConnection sending messages on closing transport (marcoagner)
53599c8 qa: Avoid start/stop of the network thread mid-test (furszy)
688190c [qa] mininode: Expose connection state through is_connected (MarcoFalke)

Pull request description:

  Part of the deep and long net and ser work that I'm doing (and Tor v3 onion addresses support). Friend of #2359.

  Focused on the end goal of implementing the `p2p_invalid_messages` functional test which validates that invalid msg headers, msg types, oversized payloads and inventory msgs aren't accepted nor can cause a resource exhaustion. And an extra covered scenario, in `p2p_invalid_tx.py`, for the orphan pool overflow.

  Plus, to get up to the goal, had to work over the functional test framework as well.

  So.. adapted list:

  * bitcoin#9045.
  * bitcoin#13512.
  * bitcoin#13517.
  * bitcoin#13715.
  * bitcoin#13747.
  * bitcoin#14456.
  * bitcoin#14522.
  * bitcoin#14672.
  * bitcoin#14693.
  * bitcoin#14812.
  * bitcoin#15246.
  * bitcoin#15330.
  * bitcoin#15697.
  * bitcoin#16445.
  * bitcoin#17931.
  * bitcoin#17469.
  * bitcoin#18628 (only `p2p_invalid_tx.py` and `p2p_invalid_messages.py`. We don't support the other tests yet).
  * bitcoin#19177.
  * bitcoin#19264.

ACKs for top commit:
  random-zebra:
    utACK 7b04c0a and merging...

Tree-SHA512: 48d1f1a6acc24a9abce033fbf1f281ba4392147da39d118a694a09d63c3e0610cc1a29d711b434b16cc0d0e030dd9f1a89843870091b6999b862b9ab18a20679
kwvg added a commit to kwvg/dash that referenced this pull request Nov 2, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Nov 3, 2021
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants