]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: make test-55-oomd less flaky
authorAnita Zhang <the.anitazha@gmail.com>
Wed, 24 Nov 2021 09:02:22 +0000 (01:02 -0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Nov 2021 11:27:30 +0000 (12:27 +0100)
Make oomctl a bit less likely to race with systemd-oomd receiving the
managed oom cgroup info by checking oomctl output in a loop with
timeout.

Fixes #21146

test/units/testsuite-55.sh

index db13964311559e54d3c1d560715e7e5081ed51f0..379ea9e56974c567cacbee5a2a731454154cbe9f 100755 (executable)
@@ -38,9 +38,20 @@ systemctl start testsuite-55-testchill.service
 systemctl start testsuite-55-testbloat.service
 
 # Verify systemd-oomd is monitoring the expected units
-oomctl | grep "/testsuite-55-workload.slice"
-oomctl | grep "20.00%"
-oomctl | grep "Default Memory Pressure Duration: 2s"
+# Try to avoid racing the oomctl output check by checking in a loop with a timeout
+oomctl_output=$(oomctl)
+timeout="$(date -ud "1 minutes" +%s)"
+while [[ $(date -u +%s) -le $timeout ]]; do
+    if grep "/testsuite-55-workload.slice" <<< "$oomctl_output"; then
+        break
+    fi
+    oomctl_output=$(oomctl)
+    sleep 1
+done
+
+grep "/testsuite-55-workload.slice" <<< "$oomctl_output"
+grep "20.00%" <<< "$oomctl_output"
+grep "Default Memory Pressure Duration: 2s" <<< "$oomctl_output"
 
 systemctl status testsuite-55-testchill.service
 
@@ -64,9 +75,20 @@ systemctl start --machine "testuser@.host" --user testsuite-55-testchill.service
 systemctl start --machine "testuser@.host" --user testsuite-55-testbloat.service
 
 # Verify systemd-oomd is monitoring the expected units
-oomctl | grep -E "/user.slice.*/testsuite-55-workload.slice"
-oomctl | grep "20.00%"
-oomctl | grep "Default Memory Pressure Duration: 2s"
+# Try to avoid racing the oomctl output check by checking in a loop with a timeout
+oomctl_output=$(oomctl)
+timeout="$(date -ud "1 minutes" +%s)"
+while [[ $(date -u +%s) -le $timeout ]]; do
+    if grep -E "/user.slice.*/testsuite-55-workload.slice" <<< "$oomctl_output"; then
+        break
+    fi
+    oomctl_output=$(oomctl)
+    sleep 1
+done
+
+grep -E "/user.slice.*/testsuite-55-workload.slice" <<< "$oomctl_output"
+grep "20.00%" <<< "$oomctl_output"
+grep "Default Memory Pressure Duration: 2s" <<< "$oomctl_output"
 
 systemctl --machine "testuser@.host" --user status testsuite-55-testchill.service