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
31e5ca4bd9f50b9e0ad5a88685225afacb073a8a
# 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
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