From: Yu Watanabe Date: Mon, 7 Apr 2025 21:56:40 +0000 (+0900) Subject: TEST-04-JOURNAL: sync journal in test script, and find journal with invocation ID X-Git-Tag: v258-rc1~869^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9e372b643bf2bfc3a3e8f7d6e16df9bcf392e1f9;p=thirdparty%2Fsystemd.git TEST-04-JOURNAL: sync journal in test script, and find journal with invocation ID Hopefully improve the stability of the test. --- diff --git a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/logs-filtering.service b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/logs-filtering.service index 4c430058cf1..6eca47d1fa4 100644 --- a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/logs-filtering.service +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/logs-filtering.service @@ -3,9 +3,8 @@ Description=Log filtering unit [Service] Type=oneshot -ExecStart=sh -c 'echo "Logging from the service, and ~more~ foo bar"' # If the service finishes extremely fast, journald cannot find the source of the # stream. Hence, we need to call 'journalctl --sync' before service finishes. -ExecStart=journalctl --sync +ExecStart=sh -c 'echo "Logging from the service, and ~more~ foo bar"; journalctl --sync' SyslogLevel=notice LogLevelMax=info diff --git a/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh b/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh index e80e78e5002..79482d60780 100755 --- a/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh +++ b/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh @@ -11,6 +11,10 @@ if ! cgroupfs_supports_user_xattrs; then exit 0 fi +# Unfortunately, journalctl -I/--invocation= is unstable when debug logging is enabled on service manager. +SAVED_LOG_LEVEL=$(systemctl log-level) +systemctl log-level info + NEEDS_RELOAD= add_logs_filtering_override() { @@ -25,17 +29,14 @@ add_logs_filtering_override() { run_service_and_fetch_logs() { local unit="${1:?}" - local start if [[ -n "$NEEDS_RELOAD" ]]; then systemctl daemon-reload NEEDS_RELOAD= fi - journalctl --sync - start="$(date '+%Y-%m-%d %T.%6N')" systemctl start "$unit" - journalctl -q -u "$unit" -S "$start" -p notice + journalctl -q -u "$unit" -I -p notice } at_exit() { @@ -91,3 +92,5 @@ add_logs_filtering_override "delegated-cgroup-filtering.service" "00-allow-all" add_logs_filtering_override "delegated-cgroup-filtering.service" "01-discard-hello" "~hello" [[ -z $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]] + +systemctl log-level "$SAVED_LOG_LEVEL" diff --git a/test/units/delegated_cgroup_filtering_payload.sh b/test/units/delegated_cgroup_filtering_payload.sh index 1181fbb9108..6084ae8dcb5 100755 --- a/test/units/delegated_cgroup_filtering_payload.sh +++ b/test/units/delegated_cgroup_filtering_payload.sh @@ -6,4 +6,7 @@ mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child echo "parent_process: hello, world!" echo "parent_process: hello, people!" -sleep 2 + +# If the service finishes extremely fast, journald cannot find the source of the +# stream. Hence, we need to call 'journalctl --sync' before service finishes. +journalctl --sync