mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-27 12:13:20 -04:00
Improve test discovery logic in get_ports.sh
The find invocation used by the bin/tests/system/get_ports.sh script
("find . -maxdepth 1 -mindepth 1 -type d") assumes the list of
directories in bin/tests/system/ remains unchanged throughout the run
time of a single system test suite. With pytest in use and the
conftest.py file now present in bin/tests/system/, that assumption is no
longer true as a __pycache__ directory may be created when the first
pytest-based test is started. Since the list of names returned by the
above find invocation serves as a fixed-size array of "port range
slots", any changes to that list during a system test suite run may lead
to port assignment collisions [1].
Fix by making the find invocation more nuanced, so that it only returns
names of directories containing test code. Squash a grep / cut pipeline
into a single awk invocation.
[1] see commit 31e5ca4bd9
(cherry picked from commit 4e0d576858)
This commit is contained in:
parent
0cc4ff04ec
commit
4847de9de1
1 changed files with 6 additions and 2 deletions
|
|
@ -14,7 +14,11 @@
|
|||
# This script is a 'port' broker. It keeps track of ports given to the
|
||||
# individual system subtests, so every test is given a unique port range.
|
||||
|
||||
total_tests=$(find . -maxdepth 1 -mindepth 1 -type d | wc -l)
|
||||
get_sorted_test_names() {
|
||||
find . -maxdepth 2 -mindepth 2 -type f \( -name "tests.sh" -o -name "tests*.py" \) | cut -d/ -f2 | sort -u
|
||||
}
|
||||
|
||||
total_tests=$(get_sorted_test_names | wc -l)
|
||||
ports_per_test=20
|
||||
|
||||
port_min=5001
|
||||
|
|
@ -33,7 +37,7 @@ while getopts "p:t:-:" OPT; do
|
|||
case "$OPT" in
|
||||
p | port) baseport=$OPTARG ;;
|
||||
t | test)
|
||||
test_index=$(find . -maxdepth 1 -mindepth 1 -type d | sort | grep -F -x -n "./${OPTARG}" | cut -d: -f1)
|
||||
test_index=$(get_sorted_test_names | awk "/^${OPTARG}\$/ { print NR }")
|
||||
if [ -z "${test_index}" ]; then
|
||||
echo "Test '${OPTARG}' not found" >&2
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue