diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bbfd057df355f6c981f588ab54649d76b3df1840..c16ff8e1727d46f7035f9d16d0ac576f8552408d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,7 +9,7 @@ build:
   # instead of calling g++ directly you can also use some build toolkit like make
   # install the necessary build tools when needed
   before_script:
-    - apt update && apt -y install libncurses-dev libmodbus-dev libsqlite3-dev libident-dev netcat
+    - apt update && apt -y install libncurses-dev libmodbus-dev libsqlite3-dev libident-dev
   script:
     - make -C src/
   artifacts:
@@ -25,5 +25,7 @@ build:
 # run tests using the binary built before
 test:
   stage: test
+  before_script:
+    - apt update && apt -y install libncurses libmodbus libsqlite3 libident netcat
   script:
     - cd tests && ./TEST_basic.sh
diff --git a/tests/TEST_basic.sh b/tests/TEST_basic.sh
index dccdc6d9b7be85d628c46c82e710837dba5a83af..481e1198452afaaee5a615e8aa57b39ff39c6fa1 100755
--- a/tests/TEST_basic.sh
+++ b/tests/TEST_basic.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-set -eux
+set -eu
 TESTNAME=basic
 
 . _common.sh
diff --git a/tests/_common.sh b/tests/_common.sh
index cb31ac766e1fe1e3338ded87c26ce9c4c574052c..fa2f1077f0235c2d7d397f3403874ced12d43382 100644
--- a/tests/_common.sh
+++ b/tests/_common.sh
@@ -1,6 +1,7 @@
 #
 # NOTE: Not a script, to be included by scripts
 #
+USER=$(id -un)
 BASEDIR=rundir/${TESTNAME}/
 PORT=22222
 
@@ -34,6 +35,7 @@ FAIL() {
 }
 TRY_COMMAND() {
 	cmd="$*"
+	echo ">> $cmd"
 	if ! $cmd ; then
 		FAIL "Command \`$cmd\` failed"
 	fi
@@ -45,8 +47,12 @@ LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise > ${
 server_pid=$!
 
 cleanup() {
-	LOG "Killing ${server_pid}"
-	kill ${server_pid}; true
+	if pidof dispsrv | grep ${server_pid}; then
+		LOG "Killing ${server_pid}"
+		kill ${server_pid}; true
+	else
+		LOG "Server already terminated"
+	fi
 }
 trap cleanup EXIT
 
@@ -57,4 +63,5 @@ if ! (echo "" | nc localhost ${PORT}); then
 	LOG "Server not responding on ${PORT}"
 	LOG "Server log contents:"
 	cat ${BASEDIR}server.log
+	exit 1
 fi