Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109015: Add test.support.socket_helper.tcp_blackhole() #109016

Merged
merged 3 commits into from
Sep 6, 2023

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 6, 2023

@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

My previous DEBUG PR: PR #108972.

See also issue #91960 "Add FreeBSD build and test using Cirrus-CI" and PR #91961 which the TCP blackhole was discussed.

@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

I validated my fix on Cirrus-CI with this patch:

diff --git a/.cirrus.yml b/.cirrus.yml
index 823b1f921d66d..2e087f1f57706 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -7,9 +7,9 @@ freebsd_task:
   # local local connections to fail with ETIMEDOUT instead of ECONNREFUSED.
   # For more information see https://reviews.freebsd.org/D41751 and
   # https://github.com/cirruslabs/cirrus-ci-docs/issues/483.
-  sysctl_script:
-    - sysctl net.inet.tcp.blackhole=0
-    - sysctl net.inet.udp.blackhole=0
+#  sysctl_script:
+#    - sysctl net.inet.tcp.blackhole=0
+#    - sysctl net.inet.udp.blackhole=0
   build_script:
     - mkdir build
     - cd build

test_asyncio failed at the first version of my PR, which proves that the Cirrus-CI did its job: test my fix :-) I had to skip 2 more tests in test_asyncio.

At the second version, it passed: Total test files: run=461/461 skipped=25 resource_denied=1 rerun=1: https://cirrus-ci.com/task/4512145228955648 (test.test_asyncio.test_subprocess had to be re-run, it's unrelated to this fix.)

cc @emaste

@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

My second patch adds skips to Lib/test/test_asyncio/test_events.py:

  • test_create_connection_local_addr_skip_different_family()
  • test_create_connection_local_addr_nomatch_family()

@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

I reverted the Cirrus CI change.

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
except KeyError:
pass

cmd = ['sysctl', name]
Copy link
Contributor

Choose a reason for hiding this comment

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

sysctl provides a -n arg to suppress the name:

$ sysctl -n net.inet.tcp.blackhole
0

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I didn't know it. It's also supported by Linux (even if right now, this function is only called on FreeBSD ;-)). I updated my PR.

@gvanrossum gvanrossum removed their request for review September 6, 2023 19:23
@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

I ran a quick test on my latest PR:

vstinner@freebsd$ sudo sysctl net.inet.tcp.blackhole=0
net.inet.tcp.blackhole: 0 -> 0
vstinner@freebsd$ ./python -m test -v test_socket -m test_connect -v
(...)
test_connect (test.test_socket.NetworkConnectionNoServer.test_connect) ... ok
(...)
Result: SUCCESS

and:

vstinner@freebsd$ sudo sysctl net.inet.tcp.blackhole=2
net.inet.tcp.blackhole: 0 -> 2

vstinner@freebsd$ ./python -m test -v test_socket -m test_connect -v
(...)
test_connect (test.test_socket.NetworkConnectionNoServer.test_connect) ... skipped 'TCP blackhole is enabled (sysctl 
(...)
Result: SUCCESS

@vstinner
Copy link
Member Author

vstinner commented Sep 6, 2023

@emaste: Would you mind to review the updated PR?

return None
output = proc.stdout

# Parse 'net.inet.tcp.blackhole: 0\n' to get '0'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is leftover

@vstinner vstinner enabled auto-merge (squash) September 6, 2023 23:28
@vstinner vstinner added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Sep 6, 2023
@vstinner vstinner merged commit a52a350 into python:main Sep 6, 2023
24 of 25 checks passed
@vstinner vstinner deleted the tcp_blackhole branch September 6, 2023 23:58
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @vstinner, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a52a3509770f29f940cda9307704908949912276 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 6, 2023
…onGH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot
Copy link

GH-109041 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Sep 6, 2023
vstinner added a commit to vstinner/cpython that referenced this pull request Sep 7, 2023
…on#109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).

(cherry picked from commit a52a350)
@bedevere-bot
Copy link

GH-109042 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Sep 7, 2023
vstinner added a commit that referenced this pull request Sep 7, 2023
…9016) (#109042)

gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).

(cherry picked from commit a52a350)
Yhg1s pushed a commit that referenced this pull request Sep 8, 2023
…109016) (#109041)

gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants