Skip to content

Commit 51d4383

Browse files
committed
Abort individual sharness tests if a previous instance is present
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.
1 parent 5d3247f commit 51d4383

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/sharness/lib/test-lib.sh

+41
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,47 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
4141

4242
# Please put go-ipfs specific shell functions below
4343

44+
###
45+
# BEGIN Check for pre-existing daemon being stuck
46+
###
47+
wait_prev_cleanup_tick_secs=1
48+
wait_prev_cleanup_max_secs=5
49+
cur_test_pwd="$(pwd)"
50+
51+
while true ; do
52+
echo -n > stuck_cwd_list
53+
54+
lsof -c ipfs -Ffn 2>/dev/null | grep -A1 '^fcwd$' | grep '^n' | cut -b 2- | while read -r pwd_of_stuck ; do
55+
case "$pwd_of_stuck" in
56+
"$cur_test_pwd"*)
57+
echo "$pwd_of_stuck" >> stuck_cwd_list
58+
;;
59+
*)
60+
;;
61+
esac
62+
done
63+
64+
test -s stuck_cwd_list || break
65+
66+
test "$wait_prev_cleanup_max_secs" -le 0 && break
67+
68+
echo "Daemons still running, waiting for ${wait_prev_cleanup_max_secs}s"
69+
sleep $wait_prev_cleanup_tick_secs
70+
71+
wait_prev_cleanup_max_secs="$(( $wait_prev_cleanup_max_secs - $wait_prev_cleanup_tick_secs ))"
72+
done
73+
74+
if test -s stuck_cwd_list ; then
75+
test_expect_success "ipfs daemon (s)seems to be running with CWDs of
76+
$(cat stuck_cwd_list)
77+
Almost certainly a leftover from a prior test, ABORTING" 'false'
78+
79+
test_done
80+
fi
81+
###
82+
# END Check for pre-existing daemon being stuck
83+
###
84+
4485
# Make sure the ipfs path is set, also set in test_init_ipfs but that
4586
# is not always used.
4687
export IPFS_PATH="$(pwd)/.ipfs"

0 commit comments

Comments
 (0)