test: fix flaky tests, retry until()

In the ongoing campaign against load-bearing sleep() and pure luck.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-02-24 06:59:29 +01:00
parent 924567f30b
commit e8c9c70e37
3 changed files with 11 additions and 10 deletions
+5 -4
View File
@@ -6,6 +6,7 @@ Verify IPv6 autoconf on a bridge is properly set up for global prefix.
See issue #473 for details.
"""
import infamy
from infamy.util import until
with infamy.Test() as test:
with test.step("Set up topology and attach to target DUT"):
@@ -42,9 +43,9 @@ with infamy.Test() as test:
})
with test.step("Verify using sysctl that 'net.ipv6.conf.br0.autoconf' is 1 on target"):
out = tgtssh.runsh("sysctl net.ipv6.conf.br0.autoconf").stdout
print(out)
if "autoconf = 1" not in out:
test.fail()
def check_autoconf():
out = tgtssh.runsh("sysctl net.ipv6.conf.br0.autoconf").stdout
return "autoconf = 1" in out
until(check_autoconf, attempts=10)
test.succeed()
+3 -3
View File
@@ -8,7 +8,7 @@ actions (log vs block/stop).
"""
import infamy
import time
from infamy.util import until
TEST_MESSAGES = [
("daemon.emerg", "Emergency: system is unusable"),
@@ -73,12 +73,12 @@ with infamy.Test() as test:
}
})
time.sleep(2)
until(lambda: tgtssh.runsh("test -f /var/log/exact-errors").returncode == 0, attempts=10)
with test.step("Send test messages at all severity levels"):
for priority, message in TEST_MESSAGES:
tgtssh.runsh(f"logger -t advtest -p {priority} '{message}'")
time.sleep(2)
until(lambda: "Error: error condition" in tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null").stdout, attempts=10)
with test.step("Verify exact-errors log contains only error messages"):
rc = tgtssh.runsh("cat /var/log/exact-errors 2>/dev/null")
+3 -3
View File
@@ -7,7 +7,7 @@ message properties with different operators, case-insensitivity, and negation.
"""
import infamy
import time
from infamy.util import until
TEST_MESSAGES = [
("myapp", "Application startup"),
@@ -90,12 +90,12 @@ with infamy.Test() as test:
}
})
time.sleep(2)
until(lambda: tgtssh.runsh("test -f /var/log/baseline").returncode == 0, attempts=10)
with test.step("Send test messages"):
for tag, msg in TEST_MESSAGES:
tgtssh.runsh(f"logger -t {tag} -p daemon.info '{msg}'")
time.sleep(1)
until(lambda: "Application startup" in tgtssh.runsh("cat /var/log/baseline 2>/dev/null").stdout, attempts=10)
with test.step("Verify myapp log contains only myapp messages"):
rc = tgtssh.runsh("grep -c 'myapp' /var/log/myapp 2>/dev/null")