]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add testcase for 'journalctl --follow --cursor-file='
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 26 May 2023 21:12:09 +0000 (06:12 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 May 2023 05:52:32 +0000 (14:52 +0900)
Also, add a FIXME comment to illustrate the issue uncovered after by
7a4ee861615101ddd2f95056cf30e69e41da86ce.

test/units/testsuite-04.sh

index 6ed41f24ea51fb277c6b40378b994f3ab92a41d1..5280cf8cb1af145710b8bb78b7a6ab844d5fcf25 100755 (executable)
@@ -161,6 +161,26 @@ journalctl --follow --file=/var/log/journal/*/* | head -n1 | grep .
 journalctl --follow --merge | head -n1 | grep .
 set -o pipefail
 
+# https://github.com/systemd/systemd/issues/26746
+rm -f /tmp/issue-26746-log /tmp/issue-26746-cursor
+ID=$(systemd-id128 new)
+
+# FIXME:
+# After the commit 7a4ee861615101ddd2f95056cf30e69e41da86ce,
+# journalctl --follow does not work if no matching entry stored in the journal.
+# To workaround the issue, we need to add an entry before calling journalctl below.
+systemd-cat -t "$ID" /bin/sh -c 'echo aaa'
+
+journalctl -t "$ID" --follow --cursor-file=/tmp/issue-26746-cursor | tee /tmp/issue-26746-log &
+systemd-cat -t "$ID" /bin/sh -c 'echo hogehoge'
+# shellcheck disable=SC2016
+timeout 10 bash -c 'while ! [[ -f /tmp/issue-26746-log && "$(cat /tmp/issue-26746-log)" =~ hogehoge ]]; do sleep .5; done'
+pkill -TERM journalctl
+test -f /tmp/issue-26746-cursor
+CURSOR_FROM_FILE=$(cat /tmp/issue-26746-cursor)
+CURSOR_FROM_JOURNAL=$(journalctl -t "$ID" --output export MESSAGE=hogehoge | sed -n -e '/__CURSOR=/ { s/__CURSOR=//; p }')
+test "$CURSOR_FROM_FILE" = "$CURSOR_FROM_JOURNAL"
+
 add_logs_filtering_override() {
     local unit="${1:?}"
     local override_name="${2:?}"