Skip to content

Commit

Permalink
Merge pull request #4756 from edsantiago/fix_kill_test_hang_safely
Browse files Browse the repository at this point in the history
Fix race condition in kill test leading to hang
  • Loading branch information
openshift-merge-robot authored Dec 29, 2019
2 parents 6897a1f + 0f78f34 commit fa551fd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ load helpers
# and confirm that signals are received. We can't use run_podman here.
local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
mkfifo $fifo
$PODMAN logs -f $cid >$fifo &
$PODMAN logs -f $cid >$fifo </dev/null &
podman_log_pid=$!

# Open the FIFO for reading, and keep it open. This prevents a race
# condition in which the container can exit (e.g. if for some reason
# it doesn't handle the signal) and we (this test) try to read from
# the FIFO. Since there wouldn't be an active writer, the open()
# would hang forever. With this exec we keep the FD open, allowing
# 'read -t' to time out and report a useful error.
exec 5<$fifo

# First container emits READY when ready; wait for it.
read -t 10 ready <$fifo
read -t 10 -u 5 ready
is "$ready" "READY" "first log message from container"

# Helper function: send the given signal, verify that it's received.
Expand All @@ -28,7 +37,7 @@ load helpers
local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1'

run_podman kill -s $signal $cid
read -t 10 actual <$fifo
read -t 10 -u 5 actual || die "Timed out: no ACK for kill -s $signal"
is "$actual" "got: $signum" "Signal $signal handled by container"
}

Expand All @@ -46,7 +55,7 @@ load helpers

# Done. Tell the container to stop, and wait for final DONE
run_podman exec $cid touch /stop
read -t 5 done <$fifo
read -t 5 -u 5 done || die "Timed out waiting for DONE from container"
is "$done" "DONE" "final log message from container"

# Clean up
Expand Down

0 comments on commit fa551fd

Please sign in to comment.