Make zombie test smarter

Instead of trying to assert that there are no zombies when the test
starts (which often fails) and to prevent conflating existing or
irrelevant zombies with the ones we are interested in checking for,
have `ps` also emit the parent process id and filter its output to
include only children of the current fish instance.
This commit is contained in:
Mahmoud Al-Qudsi 2021-03-23 02:14:20 -05:00 committed by Johannes Altmanninger
parent 9796b95f48
commit efda4f5c39

View File

@ -1,22 +1,5 @@
#RUN: %fish %s
# Ensure there's no zombies before we start, otherwise the tests will mysteriously fail.
set -l zombies_among_us
if not contains (uname) SunOS
set zombies_among_us (ps -o stat | string match 'Z*' | count)
else
# Solaris' ps is awkward, I don't know if this actually works
set zombies_among_us (ps -o s | string match 'Z*' | count)
end
[ "$zombies_among_us" -eq "0" ]
or begin
echo "Found existing zombie processes. Clean up zombies before running this test."
exit 1
end
echo "All clear of zombies."
# CHECK: All clear of zombies.
# Verify zombies are not left by disown (#7183, #5342)
# Do this first to avoid colliding with the other disowned processes below, which may
# still be running at the end of the script
@ -28,13 +11,15 @@ sleep 0.1
#CHECK: Trigger process reaping
# The initial approach here was to kill the PID of the sleep process, which should
# be gone by the time we get here. Unfortunately, kill from procps on pre-2016 distributions
# does not print an error for non-existent PIDs, so instead look for zombies in this session
# (there should be none).
# does not print an error for non-existent PIDs, so instead look for zombies in this session.
# There could already be zombies from previous tests run in this session or a test could be run
# simultaneously that causes a zombie to spawn, so limit the output only to processes started by
# this fish instance.
if not contains (uname) SunOS
ps -o stat | string match 'Z*'
ps -o ppid,stat
else
ps -o s | string match 'Z*'
end
ps -o ppid,s
end | string match -e $fish_pid | string match 'Z*'
# Verify disown can be used with last_pid, even if it is separate from the pgroup.
# This should silently succeed.