summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2020-09-26 11:58:17 +0200
committerDaiki Ueno <ueno@gnu.org>2020-10-03 16:46:38 +0200
commit9f9fb0c9ff11f3dc8a6846e647fe831ec91e6254 (patch)
tree458893eb28f97c6757997ad8364e9bfb7a7fcf47
parent54e52b9a396ccff30758a06c9b5f30241876d48b (diff)
downloadgnutls-9f9fb0c9ff11f3dc8a6846e647fe831ec91e6254.tar.gz
tests: create lock for tests using GETPORT
This fixes a race condition in the timings between when a free port is detected and when the port is actually used. Signed-off-by: Daiki Ueno <ueno@gnu.org>
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/scripts/common.sh24
2 files changed, 23 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ec5ec3f505..d4867cf3af 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -620,4 +620,4 @@ LOG_COMPILER = $(VALGRIND)
endif
distclean-local:
- rm -rf softhsm-*.db softhsm-*.config *.tmp tmp-* x509-crt-list-import-url.config.db
+ rm -rf softhsm-*.db softhsm-*.config *.tmp tmp-* x509-crt-list-import-url.config.db port.lock.d
diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh
index b9ed7eff99..396df0bfd1 100644
--- a/tests/scripts/common.sh
+++ b/tests/scripts/common.sh
@@ -66,8 +66,27 @@ check_if_port_listening() {
$PFCMD -anl|grep "[\:\.]$PORT"|grep LISTEN >/dev/null 2>&1
}
+trap "rmdir \"$top_builddir/tests/port.lock.d\" > /dev/null 2>&1 || :" 1 15 2
+
+obtain_port_lock()
+{
+ local i
+ for i in 1 2 3 4 5 6; do
+ if mkdir "$top_builddir/tests/port.lock.d" > /dev/null 2>&1; then
+ return
+ fi
+ echo "try $i: obtaining port lock"
+ sleep 2
+ done
+ return 1
+}
+
# Find a port number not currently in use.
GETPORT='
+ obtain_port_lock()
+ if $? -ne 0; then
+ echo "failed to obtain port lock: continuing anyway"
+ fi
rc=0
unset myrandom
while test $rc = 0; do
@@ -136,7 +155,7 @@ wait_for_port()
ret=$?
if test $ret != 0;then
check_if_port_in_use ${PORT}
- echo try $i
+ echo "try $i: waiting for port"
sleep 2
else
break
@@ -173,13 +192,14 @@ launch_server() {
wait_server() {
local PID=$1
- trap "test -n \"${PID}\" && kill ${PID};exit 1" 1 15 2
+ trap "test -n \"${PID}\" && kill ${PID}; exit 1" 1 15 2
wait_for_port $PORT
if test $? != 0;then
echo "Server $PORT did not come up"
kill $PID
exit 1
fi
+ rmdir "$top_builddir/tests/port.lock.d" > /dev/null 2>&1 || :
}
wait_udp_server() {