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
73 lines
2.1 KiB
Bash
Executable File
73 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
#
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
#
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
#
|
|
# See the COPYRIGHT file distributed with this work for additional
|
|
# information regarding copyright ownership.
|
|
|
|
# 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.
|
|
|
|
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
|
|
port_max=$((32767 - (total_tests * ports_per_test)))
|
|
|
|
baseport=0
|
|
test_index=0
|
|
while getopts "p:t:-:" OPT; do
|
|
if [ "$OPT" = "-" ] && [ -n "$OPTARG" ]; then
|
|
OPT="${OPTARG%%=*}"
|
|
OPTARG="${OPTARG#$OPT}"
|
|
OPTARG="${OPTARG#=}"
|
|
fi
|
|
|
|
# shellcheck disable=SC2214
|
|
case "$OPT" in
|
|
p | port) baseport=$OPTARG ;;
|
|
t | test)
|
|
test_index=$(get_sorted_test_names | awk "/^${OPTARG}\$/ { print NR }")
|
|
if [ -z "${test_index}" ]; then
|
|
echo "Test '${OPTARG}' not found" >&2
|
|
exit 1
|
|
fi
|
|
;;
|
|
-) break ;;
|
|
*) echo "invalid option" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
port_pool_size=$((port_max - port_min))
|
|
if [ "${baseport}" -eq 0 ]; then
|
|
baseport="$((($(date +%s) / 3600 % port_pool_size) + port_min + (test_index * ports_per_test)))"
|
|
fi
|
|
|
|
echo "export PORT=$((baseport))"
|
|
echo "export TLSPORT=$((baseport + 1))"
|
|
echo "export HTTPPORT=$((baseport + 2))"
|
|
echo "export HTTPSPORT=$((baseport + 3))"
|
|
echo "export EXTRAPORT1=$((baseport + 4))"
|
|
echo "export EXTRAPORT2=$((baseport + 5))"
|
|
echo "export EXTRAPORT3=$((baseport + 6))"
|
|
echo "export EXTRAPORT4=$((baseport + 7))"
|
|
echo "export EXTRAPORT5=$((baseport + 8))"
|
|
echo "export EXTRAPORT6=$((baseport + 9))"
|
|
echo "export EXTRAPORT7=$((baseport + 10))"
|
|
echo "export EXTRAPORT8=$((baseport + 11))"
|
|
echo "export CONTROLPORT=$((baseport + 12))"
|
|
|
|
# Local Variables:
|
|
# sh-basic-offset: 4
|
|
# End:
|