]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: ignore the "freezing" & "thawing" intermediate states
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 22 Jun 2021 10:12:34 +0000 (12:12 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 22 Jun 2021 10:12:34 +0000 (12:12 +0200)
When checking the unit state after `systemctl freeze|thaw` we can be
"too fast" and get the intermediate state (freezing/thawing) which we're
not interested in. Let's wait a bit and try to get the state again in
such cases to avoid unnecessary flakiness.

```
[   29.390203] testsuite-38.sh[218]: + state=thawing
[   29.390203] testsuite-38.sh[218]: + '[' thawing = running ']'
[   29.390203] testsuite-38.sh[218]: + echo 'error: unexpected freezer state, expected: running, actual: thawing'
[   29.390203] testsuite-38.sh[218]: error: unexpected freezer state, expected: running, actual: thawing
[   29.390203] testsuite-38.sh[218]: + exit 1
```

test/units/testsuite-38.sh

index 818f69bc63553bc3e84f9ca434f0de634918cfbf..e58bae81fec23d461c3b3c55134483f452bac773 100755 (executable)
@@ -82,11 +82,18 @@ check_freezer_state() {
     name="${1%.$suffix}"
     object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
 
-    state=$(busctl get-property \
-                   org.freedesktop.systemd1 \
-                   "${object_path}" \
-                   org.freedesktop.systemd1.Unit \
-                   FreezerState | cut -d " " -f2 | tr -d '"')
+    for _ in {0..10}; do
+        state=$(busctl get-property \
+                       org.freedesktop.systemd1 \
+                       "${object_path}" \
+                       org.freedesktop.systemd1.Unit \
+                       FreezerState | cut -d " " -f2 | tr -d '"')
+
+        # Ignore the intermediate freezing & thawing states in case we check
+        # the unit state too quickly
+        [[ "$state" =~ ^(freezing|thawing)$ ]] || break
+        sleep .5
+    done
 
     [ "$state" = "$2" ] || {
         echo "error: unexpected freezer state, expected: $2, actual: $state" >&2