From b81ece59c453e4f20f4d08c7f642b59ea24fcd0b Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sun, 28 Apr 2024 22:52:59 +0200 Subject: [PATCH] TEST-04-JOURNAL: Make LogFilterPatterns= tests more robust Let's use oneshot services as we don't need long running services for the tests we're doing. Let's also increase the sleeps a little as the current values weren't sufficient when running the test locally on my machine with mkosi. --- .../delegated-cgroup-filtering.service | 2 +- test/testsuite-04.units/logs-filtering.service | 3 ++- test/units/delegated_cgroup_filtering_payload.sh | 11 ++++------- .../units/delegated_cgroup_filtering_payload_child.sh | 9 +++------ test/units/testsuite-04.LogFilterPatterns.sh | 10 +++------- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/test/testsuite-04.units/delegated-cgroup-filtering.service b/test/testsuite-04.units/delegated-cgroup-filtering.service index 2c4201a27b5..a12b12ac4a6 100644 --- a/test/testsuite-04.units/delegated-cgroup-filtering.service +++ b/test/testsuite-04.units/delegated-cgroup-filtering.service @@ -2,7 +2,7 @@ Description=Test service for delegated logs filtering [Service] -Type=simple +Type=oneshot ExecStart=/usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload.sh Delegate=yes SyslogLevel=notice diff --git a/test/testsuite-04.units/logs-filtering.service b/test/testsuite-04.units/logs-filtering.service index 6e2af9a2a14..a5aba1859c8 100644 --- a/test/testsuite-04.units/logs-filtering.service +++ b/test/testsuite-04.units/logs-filtering.service @@ -2,5 +2,6 @@ Description=Log filtering unit [Service] -ExecStart=sh -c 'while true; do echo "Logging from the service, and ~more~ foo bar"; sleep .25; done' +Type=oneshot +ExecStart=sh -c 'echo "Logging from the service, and ~more~ foo bar" && sleep 2' SyslogLevel=notice diff --git a/test/units/delegated_cgroup_filtering_payload.sh b/test/units/delegated_cgroup_filtering_payload.sh index 50d01a5d4aa..7ad486bcadd 100755 --- a/test/units/delegated_cgroup_filtering_payload.sh +++ b/test/units/delegated_cgroup_filtering_payload.sh @@ -2,11 +2,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child -/bin/sh /usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload_child.sh & +/bin/sh /usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload_child.sh -while true -do - echo "parent_process: hello, world!" - echo "parent_process: hello, people!" - sleep .15 -done +echo "parent_process: hello, world!" +echo "parent_process: hello, people!" +sleep .15 diff --git a/test/units/delegated_cgroup_filtering_payload_child.sh b/test/units/delegated_cgroup_filtering_payload_child.sh index b5635b58e57..94f0d3acefc 100755 --- a/test/units/delegated_cgroup_filtering_payload_child.sh +++ b/test/units/delegated_cgroup_filtering_payload_child.sh @@ -3,9 +3,6 @@ echo $$ >/sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child/cgroup.procs -while true -do - echo "child_process: hello, world!" - echo "child_process: hello, people!" - sleep .15 -done +echo "child_process: hello, world!" +echo "child_process: hello, people!" +sleep .15 diff --git a/test/units/testsuite-04.LogFilterPatterns.sh b/test/units/testsuite-04.LogFilterPatterns.sh index d5d610fe02a..dfa9652ee29 100755 --- a/test/units/testsuite-04.LogFilterPatterns.sh +++ b/test/units/testsuite-04.LogFilterPatterns.sh @@ -18,16 +18,12 @@ add_logs_filtering_override() { run_service_and_fetch_logs() { local unit="${1:?}" - local start end + local start start="$(date '+%Y-%m-%d %T.%6N')" - systemctl restart "$unit" - sleep .5 + systemctl start "$unit" journalctl --sync - end="$(date '+%Y-%m-%d %T.%6N')" - - journalctl -q -u "$unit" -S "$start" -U "$end" -p notice - systemctl stop "$unit" + journalctl -q -u "$unit" -S "$start" -p notice } if cgroupfs_supports_user_xattrs; then -- 2.47.3