From 86fe18ddcffa3ba730837b250c4b85eda4546fb7 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 6 Nov 2025 14:40:56 +0100 Subject: [PATCH] test: sync journal after the test unit finishes In these two cases we need to sync the journal _after_ the unit finishes as well, because we try to match messages from systemd itself, not (only) from the unit, and the messages about units are dispatched asynchronously. That is, in the first case (silent-success.service) we want to make sure that LogLevelMax= filters out messages _about_ units (from systemd) as well, including messages like "Deactivated..." and "Finished...", which are sent out only when/after the unit is stopped. In the second case we try to match messages with the "systemd" syslog tag, but these messages come from systemd (obviously) and are sent out asynchronously, which means they might not reach the journal before we call `journalctl --sync` from the test unit itself, like happened here: [ 1754.150391] TEST-04-JOURNAL.sh[13331]: + systemctl start verbose-success.service [ 1754.172256] bash[13692]: success [ 1754.221210] TEST-04-JOURNAL.sh[13694]: ++ journalctl -b -q -u verbose-success.service -t systemd [ 1754.221493] TEST-04-JOURNAL.sh[13331]: + [[ -n '' ]] [ 1754.175709] systemd[1]: Starting verbose-success.service - Verbose successful service... [ 1754.221697] TEST-04-JOURNAL.sh[122]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/TEST-04-JOURNAL.journal.sh failed' [ 1754.221697] TEST-04-JOURNAL.sh[122]: Subtest /usr/lib/systemd/tests/testdata/units/TEST-04-JOURNAL.journal.sh failed [ 1754.221697] TEST-04-JOURNAL.sh[122]: + return 1 [ 1754.205408] systemd[1]: verbose-success.service: Deactivated successfully. [ 1754.205687] systemd[1]: Finished verbose-success.service - Verbose successful service. By syncing the journal after the unit is stopped we have much bigger chance that the systemd messages already reached the journal - the race is technically still there, but the chance we'd hit it should be pretty negligible. Resolves: #39555 (cherry picked from commit 7b3046e693cef3e0ce54058852deb8148254bba7) --- test/units/TEST-04-JOURNAL.journal.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/units/TEST-04-JOURNAL.journal.sh b/test/units/TEST-04-JOURNAL.journal.sh index 8834d5ae592..7fab6b52d3a 100755 --- a/test/units/TEST-04-JOURNAL.journal.sh +++ b/test/units/TEST-04-JOURNAL.journal.sh @@ -104,10 +104,12 @@ diff /tmp/expected /tmp/output # test that LogLevelMax can also suppress logging about services, not only by services systemctl start silent-success +journalctl --sync [[ -z "$(journalctl -b -q -u silent-success.service)" ]] # Test syslog identifiers exclusion systemctl start verbose-success.service +journalctl --sync [[ -n "$(journalctl -b -q -u verbose-success.service -t systemd)" ]] [[ -n "$(journalctl -b -q -u verbose-success.service -t bash)" ]] [[ -n "$(journalctl -b -q -u verbose-success.service -T systemd)" ]] -- 2.47.3