]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enforce a run time limit on unit test binaries
authorMichał Kępień <michal@isc.org>
Wed, 7 Apr 2021 09:41:45 +0000 (11:41 +0200)
committerMichał Kępień <michal@isc.org>
Wed, 7 Apr 2021 09:41:45 +0000 (11:41 +0200)
When a unit test binary hangs, the GitLab CI job in which it is run is
stuck until its run time limit is exceeded.  Furthermore, it is not
trivial to determine which test(s) hung in a given GitLab CI job based
on its log.  To prevent these issues, enforce a run time limit on every
binary executed by the lib/unit-test-driver.sh script.  Use a timeout of
5 minutes for consistency with older BIND 9 branches, which employed
Kyua for running unit tests.  Report an exit code of 124 when the run
time limit is exceeded for a unit test binary, for consistency with the
"timeout" tool included in GNU coreutils.

lib/unit-test-driver.sh.in

index 4fbd84b361ba6bcce09b5e0074b5efc4c9ba4c8d..c66649c0d1727d0bfedb2ec6695b15b34fbbc9c1 100644 (file)
@@ -9,9 +9,24 @@ if [ -z "${1}" ]; then
 fi
 
 TEST_PROGRAM="${1}"
+TIMEOUT=300
 
-"${TEST_PROGRAM}"
-STATUS=${?}
+"${TEST_PROGRAM}" &
+TEST_PROGRAM_PID=${!}
+STATUS=124
+while [ ${TIMEOUT} -gt 0 ]; do
+       if ! kill -0 "${TEST_PROGRAM_PID}" 2>/dev/null; then
+               wait "${TEST_PROGRAM_PID}"
+               STATUS=${?}
+               break
+       fi
+       sleep 1
+       TIMEOUT=$((TIMEOUT - 1))
+done
+if [ ${TIMEOUT} -eq 0 ]; then
+       echo "PID ${TEST_PROGRAM_PID} exceeded run time limit, sending SIGKILL" >&2
+       kill -KILL "${TEST_PROGRAM_PID}" 2>/dev/null
+fi
 
 TEST_PROGRAM_NAME=$(basename "${TEST_PROGRAM}")
 TEST_PROGRAM_WORK_DIR=$(dirname "${TEST_PROGRAM}")