summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2021-06-08 09:04:35 +0200
committerAnita Zhang <the.anitazha@gmail.com>2021-06-09 21:04:56 +0200
commit0c81900965a72b29eb76e0737ed899b925ee75b6 (patch)
treea8a628157169dad20fd554e21c5fdf2ee737035c
parentman: update docs on systemd-system.conf logging (LogTime=) (#19846) (diff)
downloadsystemd-0c81900965a72b29eb76e0737ed899b925ee75b6.tar.xz
systemd-0c81900965a72b29eb76e0737ed899b925ee75b6.zip
test: add extended test for triggering mount rate limit
It's hard to trigger the failure to exit the rate limit state in isolation as it needs multiple event sources in order to show that it gets stuck in the queue. Hence why this is an extended test.
l---------test/TEST-60-MOUNT-RATELIMIT/Makefile1
-rwxr-xr-xtest/TEST-60-MOUNT-RATELIMIT/test.sh7
-rw-r--r--test/units/testsuite-60.service6
-rwxr-xr-xtest/units/testsuite-60.sh73
4 files changed, 87 insertions, 0 deletions
diff --git a/test/TEST-60-MOUNT-RATELIMIT/Makefile b/test/TEST-60-MOUNT-RATELIMIT/Makefile
new file mode 120000
index 0000000000..e9f93b1104
--- /dev/null
+++ b/test/TEST-60-MOUNT-RATELIMIT/Makefile
@@ -0,0 +1 @@
+../TEST-01-BASIC/Makefile \ No newline at end of file
diff --git a/test/TEST-60-MOUNT-RATELIMIT/test.sh b/test/TEST-60-MOUNT-RATELIMIT/test.sh
new file mode 100755
index 0000000000..f9eb11ccb4
--- /dev/null
+++ b/test/TEST-60-MOUNT-RATELIMIT/test.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -e
+TEST_DESCRIPTION="Test that mount/unmount storms can enter/exit rate limit state and will not leak units"
+
+. $TEST_BASE_DIR/test-functions
+
+do_test "$@"
diff --git a/test/units/testsuite-60.service b/test/units/testsuite-60.service
new file mode 100644
index 0000000000..3715c4f341
--- /dev/null
+++ b/test/units/testsuite-60.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=TEST-60-MOUNT-RATELIMIT
+
+[Service]
+Type=oneshot
+ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
diff --git a/test/units/testsuite-60.sh b/test/units/testsuite-60.sh
new file mode 100755
index 0000000000..8158754667
--- /dev/null
+++ b/test/units/testsuite-60.sh
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+set -eux
+set -o pipefail
+
+systemd-analyze log-level debug
+systemd-analyze log-target journal
+
+NUM_DIRS=20
+
+# mount/unmount enough times to trigger the /proc/self/mountinfo parsing rate limiting
+
+for ((i = 0; i < NUM_DIRS; i++)); do
+ mkdir "/tmp/meow${i}"
+done
+
+for ((i = 0; i < NUM_DIRS; i++)); do
+ mount -t tmpfs tmpfs "/tmp/meow${i}"
+done
+
+systemctl daemon-reload
+systemctl list-units -t mount tmp-meow* | grep -q tmp-meow
+
+for ((i = 0; i < NUM_DIRS; i++)); do
+ umount "/tmp/meow${i}"
+done
+
+# figure out if we have entered the rate limit state
+
+exited_rl=0
+timeout="$(date -ud "2 minutes" +%s)"
+while [[ $(date -u +%s) -le ${timeout} ]]; do
+ if journalctl -u init.scope | grep -q "(mount-monitor-dispatch) entered rate limit"; then
+ entered_rl=1
+ break
+ fi
+ sleep 5
+done
+
+# if the infra is slow we might not enter the rate limit state; in that case skip the exit check
+
+if [ "${entered_rl}" = "1" ]; then
+ exited_rl=0
+ timeout="$(date -ud "2 minutes" +%s)"
+ while [[ $(date -u +%s) -le ${timeout} ]]; do
+ if journalctl -u init.scope | grep -q "(mount-monitor-dispatch) left rate limit"; then
+ exited_rl=1
+ break
+ fi
+ sleep 5
+ done
+
+ if [ "${exited_rl}" = "0" ]; then
+ exit 24
+ fi
+fi
+
+# give some time for units to settle so we don't race between exiting the rate limit state and cleaning up the units
+
+sleep 60
+systemctl daemon-reload
+sleep 60
+
+# verify that the mount units are always cleaned up at the end
+
+if systemctl list-units -t mount tmp-meow* | grep -q tmp-meow; then
+ exit 42
+fi
+
+systemd-analyze log-level info
+
+echo OK >/testok
+
+exit 0