Skip to content

Commit

Permalink
tests: prepare memory limit before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
maykathm authored and ndyer committed Dec 18, 2024
1 parent 554ba31 commit 63db199
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions tests/lib/prepare-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,13 @@ prepare_suite_each() {
return 0
fi

# shellcheck source=tests/lib/prepare.sh
. "$TESTSLIB"/prepare.sh
# Each individual task may potentially set the SNAP_NO_MEMORY_LIMIT variable
prepare_memory_limit_override

if [[ "$variant" = full ]]; then
if os.query is-classic; then
# shellcheck source=tests/lib/prepare.sh
. "$TESTSLIB"/prepare.sh
prepare_each_classic
fi
fi
Expand Down
21 changes: 12 additions & 9 deletions tests/lib/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,6 @@ update_core_snap_for_classic_reexec() {
}

prepare_memory_limit_override() {
# First time it is needed to save the initial env var value
if not tests.env is-set initial SNAPD_NO_MEMORY_LIMIT; then
tests.env set initial SNAPD_NO_MEMORY_LIMIT "$SNAPD_NO_MEMORY_LIMIT"
# Then if the new value is the same than the initial, then no new configuration needed
elif [ "$(tests.env get initial SNAPD_NO_MEMORY_LIMIT)" = "$SNAPD_NO_MEMORY_LIMIT" ]; then
return
fi

# set up memory limits for snapd bu default unless explicit requested not to
# or the system is known to be problematic
local set_limit=1
Expand All @@ -279,6 +271,18 @@ prepare_memory_limit_override() {
;;
esac

# If we don't wish to impose a memory limit, and the conf file
# already doesn't exist, then no new configuration is needed
if [ "$set_limit" == "0" ] && ! [ -f "/etc/systemd/system/snapd.service.d/memory-max.conf" ]; then
return
fi

# If we wish to impose a memory limit, and the conf file
# already exists, then no new configuration is needed
if [ "$set_limit" == "1" ] && [ -f "/etc/systemd/system/snapd.service.d/memory-max.conf" ]; then
return
fi

if [ "$set_limit" = "0" ]; then
# make sure the file does not exist then
rm -f /etc/systemd/system/snapd.service.d/memory-max.conf
Expand Down Expand Up @@ -338,7 +342,6 @@ prepare_each_classic() {
fi

prepare_reexec_override
prepare_memory_limit_override
}

prepare_classic() {
Expand Down

0 comments on commit 63db199

Please sign in to comment.