Skip to content

Commit afc68a4

Browse files
committed
test: Wait for children to exit
* Clean-up processes properly.
1 parent 1c55356 commit afc68a4

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

test/client/wait-for-connect.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ set -e
55

66
OPENVPN_CONFIG=${1:-/client/config.ovpn}
77

8-
# Run in background, rely on bash for job management
8+
# Run in background using bash job management, setup trap to clean-up
9+
trap "{ jobs -p | xargs -r kill; wait; }" EXIT
910
openvpn --config "$OPENVPN_CONFIG" --management 127.0.0.1 9999 &
1011

1112
# Spin waiting for interface to exist signifying connection
@@ -31,8 +32,6 @@ done
3132

3233
if [ $i -ge $timeout ]; then
3334
echo "Error starting OpenVPN, i=$i, exiting."
34-
exit 2;
35+
exit 2
3536
fi
3637

37-
# The show is over.
38-
kill %1

test/tests/basic/run.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ docker run -v $OVPN_DATA:/etc/openvpn --rm $IMG ovpn_getclient $CLIENT | tee $CL
2222
docker run -v $OVPN_DATA:/etc/openvpn --rm $IMG ovpn_listclients | grep $CLIENT
2323

2424
#
25-
# Fire up the server
25+
# Fire up the server and setup a trap to always clean it up
2626
#
27+
trap "{ jobs -p | xargs -r kill; wait; }" EXIT
2728
docker run --name "ovpn-test" -v $OVPN_DATA:/etc/openvpn --rm -p 1194:1194/udp --privileged $IMG &
2829

2930
#for i in $(seq 10); do
@@ -39,10 +40,6 @@ docker run --name "ovpn-test" -v $OVPN_DATA:/etc/openvpn --rm -p 1194:1194/udp -
3940
#
4041
docker run --rm --net=host --privileged --volume $CLIENT_DIR:/client $IMG /client/wait-for-connect.sh
4142

42-
#
43-
# Client either connected or timed out, kill server
44-
#
45-
kill %1
4643

4744
#
4845
# Celebrate

test/tests/dual-proto/run.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ docker run -v $OVPN_DATA:/etc/openvpn --rm $IMG ovpn_listclients | grep $CLIENT_
3535
# Fire up the server
3636
#
3737

38-
# run in shell bg to get logs
38+
# Run in shell bg to get logs, setup trap to clean-up
39+
trap "{ jobs -p | xargs -r kill; wait; }" EXIT
3940
docker run --name "ovpn-test-udp" -v $OVPN_DATA:/etc/openvpn --rm -p 1194:1194/udp --privileged $IMG &
4041
docker run --name "ovpn-test-tcp" -v $OVPN_DATA:/etc/openvpn --rm -p 443:1194/tcp --privileged $IMG ovpn_run --proto tcp &
4142

@@ -47,10 +48,6 @@ docker run --name "ovpn-test-tcp" -v $OVPN_DATA:/etc/openvpn --rm -p 443:1194/tc
4748
docker run --rm --net=host --privileged --volume $CLIENT_DIR:/client $IMG /client/wait-for-connect.sh
4849
docker run --rm --net=host --privileged --volume $CLIENT_DIR:/client $IMG /client/wait-for-connect.sh "/client/config-tcp.ovpn"
4950

50-
#
51-
# Client either connected or timed out, kill server
52-
#
53-
kill %1 %2
5451

5552
#
5653
# Celebrate

test/tests/otp/run.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ grep 'reneg-sec 0' $CLIENT_DIR/config.ovpn || abort 'reneg-sec not set to 0 in c
4949
#
5050
# Fire up the server
5151
#
52+
trap "{ jobs -p | xargs -r kill; wait; }" EXIT
5253
docker run --name "ovpn-test" -v $OVPN_DATA:/etc/openvpn --rm -p 1194:1194/udp --privileged $IMG &
5354

5455
#for i in $(seq 10); do
@@ -64,10 +65,6 @@ docker run --name "ovpn-test" -v $OVPN_DATA:/etc/openvpn --rm -p 1194:1194/udp -
6465
#
6566
docker run --rm --net=host --privileged --volume $CLIENT_DIR:/client $IMG /client/wait-for-connect.sh
6667

67-
#
68-
# Client either connected or timed out, kill server
69-
#
70-
kill %1
7168

7269
#
7370
# Celebrate

test/tests/revocation/run.sh

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function finish {
2323
# Stop the server and clean up
2424
docker rm -f $NAME
2525
docker volume rm $OVPN_DATA
26+
jobs -p | xargs -r kill
27+
wait
2628
}
2729
trap finish EXIT
2830

0 commit comments

Comments
 (0)