Skip to content

Commit

Permalink
tests: make flock check in tests/main/snap-remove-terminate more robu…
Browse files Browse the repository at this point in the history
…st (#14514)

* tests: make flock check in tests/main/snap-remove-terminate more robust

The flock check was testing that the service just created has held the
flock immediately. In some cases the test service wasn't able to hold
the lock fast enough.

Instead, check that a file is created by the service to confirm the
snap is run by the service.

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* tests: fix shellcheck

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

* tests: address review comments

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>

---------

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
  • Loading branch information
ZeyadYasser authored Sep 18, 2024
1 parent dcea5dc commit 6ca1b59
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/main/snap-remove-terminate/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ restore: |
systemctl stop test-kill.service || true
systemctl reset-failed test-kill.service || true
debug: |
journalctl -u test-kill.service
execute: |
echo "Start a long running process"
lockfile="$(pwd)/lockfile"
touch "$lockfile"
sh_snap_bin="$(command -v test-snapd-sh.sh)"
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c "sleep 100000"
systemd-run --unit test-kill.service flock "$lockfile" "$sh_snap_bin" -c 'touch /var/snap/test-snapd-sh/common/alive; sleep 100000'
# Wait for service to be up
retry -n 10 systemctl is-active test-kill.service
retry -n 10 test -f /var/snap/test-snapd-sh/common/alive
echo "Lock is held"
not flock --timeout 0 "$lockfile" --command "true"
Expand Down

0 comments on commit 6ca1b59

Please sign in to comment.