Skip to content

Commit

Permalink
Merge pull request #120 from tgross/zombie_reap_race
Browse files Browse the repository at this point in the history
Avoid racing reparent in zombie-reaping integration test
  • Loading branch information
tgross committed Mar 29, 2016
2 parents 4664155 + 5bf07d1 commit ca59479
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions integration_tests/tests/test_reap_zombies/run.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/bash
# Test to verify that we're correctly reaping zombies.
# At any given time we may have up to 1 zombie parented to PID1 (it has been
# reparented but not yet reaped) and 1 zombie not yet parented to PID1.
# We can't test any more precisely than this without racing the kernel
# reparenting mechanism.

docker-compose up -d consul app > /dev/null 2>&1
APP_ID="$(docker-compose ps -q app)"
sleep 6
NUM_ZOMBIES=$(docker exec $APP_ID ps -o stat,ppid,pid,comm | awk '

PTREE=$(docker exec $APP_ID ps -o stat,ppid,pid,comm)
REPARENTED_ZOMBIES=$(echo $PTREE | awk '
BEGIN { count=0 }
$1 ~ /^Z/ && $2 ~ /^1$/ { count++ }
END { print count }
')

TOTAL_ZOMBIES=$(echo $PTREE | awk '
BEGIN { count=0 }
$1 ~ /^Z/ && $2 ~ /1/ { count++ }
$1 ~ /^Z/ { count++ }
END { print count }
')
if [ $NUM_ZOMBIES -gt 1 ]; then
echo "Number of zombies > 1: $NUM_ZOMBIES" >&2
docker exec $APP_ID ps -o stat,ppid,pid,args

if [ $REPARENTED_ZOMBIES -gt 1 ] || [ $TOTAL_ZOMBIES -gt 2 ]; then
echo "More than permitted number of zombies." >&2
echo $PTREE >&2
docker logs $APP_ID
exit 1
fi
Expand Down

0 comments on commit ca59479

Please sign in to comment.