Skip to content

Commit

Permalink
tests: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Zeyad Gouda <[email protected]>
  • Loading branch information
ZeyadYasser committed Sep 19, 2024
1 parent 84bdbfb commit 55b74c3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion tests/lib/snaps/fork-bomb/bin/bomb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

bomb() {
bomb | bomb &
#shellcheck disable=SC2264
bomb | bomb &
}; bomb
3 changes: 3 additions & 0 deletions tests/lib/snaps/fork-bomb/bin/sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec /bin/sh "$@"
8 changes: 6 additions & 2 deletions tests/lib/snaps/fork-bomb/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: fork-bomb
version: 1.0
base: core24
license: GPL-3.0
apps:
fork-bomb:
command: bin/bomb
fork-bomb:
command: bin/bomb
sh:
command: bin/sh

description: |
A fork bomb as the name suggests
19 changes: 6 additions & 13 deletions tests/main/snap-remove-terminate/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ environment:
BAD_SNAP/no_fork_bomb: no-fork-bomb

prepare: |
if [ "$BAD_SNAP" = "fork-bomb" ]; then
"$TESTSTOOLS"/snaps-state install-local fork-bomb
else
snap install test-snapd-sh
fi
"$TESTSTOOLS"/snaps-state install-local fork-bomb
restore: |
systemctl stop test-kill.service || true
Expand All @@ -31,11 +27,12 @@ execute: |
lockfile="$(pwd)/lockfile"
touch "$lockfile"
sh_snap_bin="$(command -v fork-bomb.sh)"
if [ "$BAD_SNAP" = "fork-bomb" ]; then
sh_snap_bin="$(command -v fork-bomb)"
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin"
#shellcheck disable=SC2016
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c 'touch /var/snap/test-snapd-sh/common/alive; $SNAP/bin/fork-bomb'
else
sh_snap_bin="$(command -v test-snapd-sh.sh)"
#shellcheck disable=SC2016
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c 'touch /var/snap/test-snapd-sh/common/alive; sleep 100000'
fi
# Wait for service to be up
Expand All @@ -45,11 +42,7 @@ execute: |
not flock --timeout 0 "$lockfile" --command "true"
echo "Remove snap with --terminate flag"
if [ "$BAD_SNAP" = "fork-bomb" ]; then
snap remove --terminate fork-bomb
else
snap remove --terminate test-snapd-sh
fi
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"

0 comments on commit 55b74c3

Please sign in to comment.