1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
summary: Ensure that the remove --terminate flag kills running snap apps.
details: |
This test spawns a snap app background process and checks that it
gets terminated when removing with the --terminate flag.
systems:
# Ubuntu 14.04's special version of systemd doesn't have StartTransientUnit API.
- -ubuntu-14.04-*
kill-timeout: 10m
environment:
BAD_SNAP/fork_bomb: fork-bomb
BAD_SNAP/no_fork_bomb: no-fork-bomb
prepare: |
"$TESTSTOOLS"/snaps-state install-local fork-bomb
if [ "$BAD_SNAP" = "fork-bomb" ]; then
tests.session -u test prepare
uid="$(id -u test)"
systemctl set-property "user-$uid.slice" TasksMax=1000
fi
restore: |
if [ "$BAD_SNAP" = "fork-bomb" ]; then
tests.session -u test restore
tests.session -u test exec systemctl --user stop test-kill.service || true
tests.session -u test exec systemctl --user reset-failed test-kill.service || true
else
systemctl stop test-kill.service || true
systemctl reset-failed test-kill.service || true
fi
debug: |
journalctl -u test-kill.service
execute: |
echo "Start a long running process"
lockfile="$(pwd)/lockfile"
touch "$lockfile"
alive_check="/var/snap/fork-bomb/common/alive"
sh_snap_bin="$(command -v fork-bomb.sh)"
if [ "$BAD_SNAP" = "fork-bomb" ]; then
if [[ "$SPREAD_SYSTEM" = amazon-linux-2-* ]]; then
# Amazon Linux 2 does not support systemd --user (see tests/main/tests.session-support for details)
echo "Skipping because systemd --user is not supported"
exit 0
fi
#shellcheck disable=SC2016,SC2086
alive_check="$(tests.session -u test exec $sh_snap_bin -c 'echo $SNAP_USER_COMMON/alive')"
#shellcheck disable=SC2016
tests.session -u test exec systemd-run --user --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c 'touch $SNAP_USER_COMMON/alive; sleep 100000'
else
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c 'touch /var/snap/fork-bomb/common/alive; sleep 100000'
fi
# Wait for snap to start
retry -n 10 test -f "$alive_check"
echo "Lock is held"
not flock --timeout 0 "$lockfile" --command "true"
echo "Remove snap with --terminate flag"
snap remove --terminate fork-bomb
echo "Running process should be terminated after remove change is complete and lockfile should be unlocked"
flock --timeout 60 "$lockfile" --command "true"
|