Skip to content

Commit

Permalink
Abort individual sharness tests if a previous instance is present
Browse files Browse the repository at this point in the history
Before starting each individual test check if a daemon is present with a
trash* directory as its workdir. Exit with failure if this is the case.
  • Loading branch information
ribasushi committed Mar 15, 2020
1 parent 5d3247f commit 51d4383
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,47 @@ SHARNESS_LIB="lib/sharness/sharness.sh"

# Please put go-ipfs specific shell functions below

###
# BEGIN Check for pre-existing daemon being stuck
###
wait_prev_cleanup_tick_secs=1
wait_prev_cleanup_max_secs=5
cur_test_pwd="$(pwd)"

while true ; do
echo -n > stuck_cwd_list

lsof -c ipfs -Ffn 2>/dev/null | grep -A1 '^fcwd$' | grep '^n' | cut -b 2- | while read -r pwd_of_stuck ; do
case "$pwd_of_stuck" in
"$cur_test_pwd"*)
echo "$pwd_of_stuck" >> stuck_cwd_list
;;
*)
;;
esac
done

test -s stuck_cwd_list || break

test "$wait_prev_cleanup_max_secs" -le 0 && break

echo "Daemons still running, waiting for ${wait_prev_cleanup_max_secs}s"
sleep $wait_prev_cleanup_tick_secs

wait_prev_cleanup_max_secs="$(( $wait_prev_cleanup_max_secs - $wait_prev_cleanup_tick_secs ))"
done

if test -s stuck_cwd_list ; then
test_expect_success "ipfs daemon (s)seems to be running with CWDs of
$(cat stuck_cwd_list)
Almost certainly a leftover from a prior test, ABORTING" 'false'

test_done
fi
###
# END Check for pre-existing daemon being stuck
###

# Make sure the ipfs path is set, also set in test_init_ipfs but that
# is not always used.
export IPFS_PATH="$(pwd)/.ipfs"
Expand Down

0 comments on commit 51d4383

Please sign in to comment.