-
Notifications
You must be signed in to change notification settings - Fork 38.7k
tests: Allow tests to use a loopback address other than 127.0.0.1 for more test runner parallelism #26841
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
Conversation
The next commit will be replacing 127.0.0.1 with LOCALHOST in the functional tests, so the tests that will have this done need to import it.
-BEGIN VERIFY SCRIPT-
sed -E -i -e ":a;s/(f[\'\"].+?)127.0.0.1/\1{LOCALHOST}/;ta" $(git grep -El "f['\"]\S+?127.0.0.1" -- "test/functional/" ":!test/functional/test_framework/util.py" ":!test/functional/rpc_bind.py")
sed -E -i -e ":a;s/['\"]127.0.0.1['\"]/LOCALHOST/;ta" $(git grep -El "['\"]127.0.0.1['\"]" -- "test/functional/*" ":!test/functional/test_framework/util.py" ":!test/functional/rpc_bind.py")
sed -E -i -e ":a;s/(['\"]\S*?)127.0.0.1/f\1{LOCALHOST}/;ta" $(git grep -El "['\"](\S*?)127.0.0.1" -- "test/functional/" ":!test/functional/test_framework/util.py" ":!test/functional/rpc_bind.py")
sed -E -i -e "s/127.0.0.1:/{LOCALHOST}:/" $(git grep -El "127.0.0.1:" -- "test/functional/" ":!test/functional/test_framework/util.py" ":!test/functional/rpc_bind.py")
-END VERIFY SCRIPT-
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Someone pointed out to me that the same thing could be achieved without modifying anything by using network namespaces, so closing in favor of doing that. For this interested, here's what I do now for each instance I want to run (scripted, of course): ip netns add bitcoin_test_netns_1
ip netns exec bitcoin_test_netns_1 ip link set dev lo up
ip netns exec bitcoin_test_netns_1 ip link add dum0 type dummy
ip netns exec bitcoin_test_netns_1 ip addr add 10.1.1.1/32 dev dum0
ip netns exec bitcoin_test_netns_1 ip link set dum0 up
ip netns exec bitcoin_test_netns_1 sudo -u $(whoami) test/functional/test_runner.py -j 60This results in successfully running all of the tests that would normally be run, and without interfering with each other. |
I often need to run multiple test_runner.py instances in parallel and the tests will often have port conflicts with other tests being run. While setting
TEST_RUNNER_PORT_MINcan help, the number of test instances that can be run is still limited by the number of free ports for the 127.0.0.1 address, and it quickly runs into ports being used by other software at the high end of the port range. However it occurred to me that 127.0.0.1 is not the only loopback address available, and having the tests use different addresses allows us to avoid port conflicts as the other addresses are pretty much unused. This PR introduces a new environment variableBITCOIN_TEST_BINDwhich can specify an ip address for spawned nodes to bind to. By specifying different loopback addresses for each test_runner.py instance, I can completely avoid port conflicts and run many more in parallel.In order for the tests to work, the host needs to be setup to have the specified addresses bound to the loopback interface. This can be achieved with a command like
ip addr add 127.0.0.2/32 dev lowhich would allowenv BITCOIN_TEST_BIND=127.0.0.2 test/functional/test_runner.pyto work.References to 127.0.0.1 have been (mostly) changed to
LOCALHOSTwhich will match the value specified inBITCOIN_TEST_BIND, with the default being 127.0.0.1.