]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #23941 from yuwata/test-60-improve-performance
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 8 Jul 2022 07:24:52 +0000 (07:24 +0000)
committerGitHub <noreply@github.com>
Fri, 8 Jul 2022 07:24:52 +0000 (07:24 +0000)
test: performance improvement for TEST-60

test/units/testsuite-60.service
test/units/testsuite-60.sh

index 18024d12d2151a0468cf4afb35fc488cc6310574..1a929e4fd9d405210d3b26698cdf13abc2ef5e75 100644 (file)
@@ -4,4 +4,5 @@ Description=TEST-60-MOUNT-RATELIMIT
 
 [Service]
 Type=oneshot
+ExecStartPre=rm -f /failed /testok
 ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
index 3a097816cad7710126f293e456c5f8b6bc10ce50..3c391c8efa6ddf488eab3ebc9ce1e7c34cc570e7 100755 (executable)
@@ -53,6 +53,8 @@ EOF
     }
 }
 
+: >/failed
+
 systemd-analyze log-level debug
 systemd-analyze log-target journal
 
@@ -83,6 +85,8 @@ for ((i = 0; i < NUM_DIRS; i++)); do
     mkdir "/tmp/meow${i}"
 done
 
+TS="$(date '+%H:%M:%S')"
+
 for ((i = 0; i < NUM_DIRS; i++)); do
     mount -t tmpfs tmpfs "/tmp/meow${i}"
 done
@@ -94,54 +98,20 @@ for ((i = 0; i < NUM_DIRS; i++)); do
     umount "/tmp/meow${i}"
 done
 
-# figure out if we have entered the rate limit state
-
-entered_rl=0
-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
+# Figure out if we have entered the rate limit state.
+# If the infra is slow we might not enter the rate limit state; in that case skip the exit check.
+if timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; done"; then
+    timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; done"
 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
+# Verify that the mount units are always cleaned up at the end.
+# Give some time for units to settle so we don't race between exiting the rate limit state and cleaning up the units.
+timeout 2m bash -c 'while systemctl list-units -t mount tmp-meow* | grep -q tmp-meow; do systemctl daemon-reload; sleep 10; done'
 
 # test that handling of mount start jobs is delayed when /proc/self/mouninfo monitor is rate limited
 test_issue_20329
 
 systemd-analyze log-level info
 
-echo OK >/testok
-
-exit 0
+touch /testok
+rm /failed