@cryptotaxi247 / kubo / commits / 51d4383d5

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.

Peter Rabbitson committed Dec 14, 2019 at 18:59 UTC 51d4383d567fdced88b275597cfe7483ec0350dd
1 file changed +41
test/sharness/lib/test-lib.sh
+41
@@ -41,6 +41,47 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
41
42 # Please put go-ipfs specific shell functions below
43
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 +
85 # Make sure the ipfs path is set, also set in test_init_ipfs but that
86 # is not always used.
87 export IPFS_PATH="$(pwd)/.ipfs"