Skip to content

Commit e26c9d0

Browse files
Add test.
1 parent ac74e4f commit e26c9d0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/002-test-signal-handler.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ test_signal_handler_nomad_job() {
2020
exit 1
2121
fi
2222

23+
# Even though $(nomad job status) reports signal job status as "running"
24+
# The actual container process might not be running yet.
25+
# We need to wait for actual container to start running before trying to send invalid signal.
26+
echo "INFO: Wait for signal container to get into RUNNING state, before trying to send invalid signal."
27+
is_signal_container_active
28+
29+
echo "INFO: Test invalid signal."
30+
alloc_id=$(nomad job status signal|awk 'END{print}'|cut -d ' ' -f 1)
31+
local outfile=$(mktemp /tmp/signal.XXXXXX)
32+
nomad alloc signal -s INVALID $alloc_id >> $outfile 2>&1
33+
if ! grep -q "Invalid signal" $outfile; then
34+
echo "ERROR: Invalid signal didn't error out."
35+
cleanup "$outfile"
36+
exit 1
37+
fi
38+
cleanup "$outfile"
39+
2340
echo "INFO: Stopping nomad signal handler job."
2441
nomad job stop signal
2542
signal_status=$(nomad job status -short signal|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')
@@ -33,4 +50,29 @@ test_signal_handler_nomad_job() {
3350
popd
3451
}
3552

53+
cleanup() {
54+
local tmpfile=$1
55+
rm $tmpfile > /dev/null 2>&1
56+
}
57+
58+
is_signal_container_active() {
59+
i="0"
60+
while test $i -lt 5
61+
do
62+
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
63+
if [ $? -eq 0 ]; then
64+
echo "INFO: signal container is up and running"
65+
break
66+
fi
67+
echo "INFO: signal container is down, sleep for 4 seconds."
68+
sleep 4s
69+
i=$[$i+1]
70+
done
71+
72+
if [ $i -ge 5 ]; then
73+
echo "ERROR: signal container didn't come up. exit 1."
74+
exit 1
75+
fi
76+
}
77+
3678
test_signal_handler_nomad_job

tests/003-test-capabilities.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ is_capabilities_container_active() {
8181
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
8282
if [ $? -eq 0 ]; then
8383
echo "INFO: capabilities container is up and running"
84+
sleep 5s
8485
break
8586
fi
8687
echo "INFO: capabilities container is down, sleep for 4 seconds."

0 commit comments

Comments
 (0)