From: Frantisek Sumsal Date: Thu, 23 Oct 2025 08:28:07 +0000 (+0200) Subject: test: properly wait for the forked process X-Git-Tag: v259-rc1~257 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c05758663b162c64da4729944023dec8cf684c75;p=thirdparty%2Fsystemd.git test: properly wait for the forked process The process forked off by `systemd-notify --fork` is not a child of the current shell, so using `wait` doesn't work. This then later causes a race, when the test occasionally fails because it attempts to start a new systemd-socket-activate instance before the old one is completely gone: [ 1488.947744] TEST-74-AUX-UTILS.sh[1938]: Child 1947 died with code 0 [ 1488.947952] TEST-74-AUX-UTILS.sh[1933]: + assert_eq hello hello [ 1488.949716] TEST-74-AUX-UTILS.sh[1948]: + set +ex [ 1488.950112] TEST-74-AUX-UTILS.sh[1950]: ++ cat /proc/1938/comm [ 1488.945555] systemd[1]: Started systemd-networkd.service - Network Management. [ 1488.950365] TEST-74-AUX-UTILS.sh[1933]: + assert_in systemd-socket systemd-socket- [ 1488.950563] TEST-74-AUX-UTILS.sh[1951]: + set +ex [ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + kill 1938 [ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + wait 1938 [ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: .//usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh: line 14: wait: pid 1938 is not a child of this shell [ 1488.950766] TEST-74-AUX-UTILS.sh[1933]: + : [ 1488.951486] TEST-74-AUX-UTILS.sh[1952]: ++ systemd-notify --fork -- systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE [ 1488.952222] TEST-74-AUX-UTILS.sh[1953]: Failed to listen on [::]:1234: Address already in use [ 1488.952222] TEST-74-AUX-UTILS.sh[1953]: Failed to open '1234': Address already in use [ 1488.956831] TEST-74-AUX-UTILS.sh[1933]: + PID=1953 [ 1488.957078] TEST-74-AUX-UTILS.sh[102]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh failed' [ 1488.957078] TEST-74-AUX-UTILS.sh[102]: Subtest /usr/lib/systemd/tests/testdata/units/TEST-74-AUX-UTILS.socket-activate.sh failed --- diff --git a/test/units/TEST-74-AUX-UTILS.socket-activate.sh b/test/units/TEST-74-AUX-UTILS.socket-activate.sh index 4e61d7c0e12..d4506dd4112 100755 --- a/test/units/TEST-74-AUX-UTILS.socket-activate.sh +++ b/test/units/TEST-74-AUX-UTILS.socket-activate.sh @@ -11,7 +11,7 @@ assert_in systemd-socket "$(cat /proc/"$PID"/comm)" assert_eq "$(echo -n hello | socat - 'TCP:localhost:1234')" hello assert_in systemd-socket "$(cat /proc/"$PID"/comm)" kill "$PID" -wait "$PID" || : +tail --pid="$PID" -f /dev/null PID=$(systemd-notify --fork -- systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE) for _ in {1..100}; do @@ -24,7 +24,7 @@ for _ in {1..100}; do if [[ "$(cat /proc/"$PID"/comm || :)" =~ socat ]]; then assert_eq "$(echo -n bye | socat - 'TCP:localhost:1234')" bye - wait "$PID" || : + tail --pid="$PID" -f /dev/null break fi done