test: ignore errors during test cleanup, so cleanup can finish

Also move TESTDIR and STATEFILE removal into test_cleanup
This commit is contained in:
Dan Streetman 2019-07-12 14:09:48 -04:00
parent ec4cab49c9
commit f85bc044e5
2 changed files with 18 additions and 17 deletions

View file

@ -83,7 +83,8 @@ cleanup_root_var() {
} }
test_cleanup() { test_cleanup() {
cleanup_root_var # ignore errors, so cleanup can continue
cleanup_root_var || true
_test_cleanup _test_cleanup
} }

View file

@ -1706,14 +1706,20 @@ test_setup_cleanup() {
} }
_test_cleanup() { _test_cleanup() {
if mountpoint $TESTDIR/root; then # (post-test) cleanup should always ignore failure and cleanup as much as possible
ddebug "umount $TESTDIR/root" (
umount $TESTDIR/root set +e
fi if mountpoint $TESTDIR/root; then
if [[ $LOOPDEV && -b $LOOPDEV ]]; then ddebug "umount $TESTDIR/root"
ddebug "losetup -d $LOOPDEV" umount $TESTDIR/root
losetup -d $LOOPDEV fi
fi if [[ $LOOPDEV && -b $LOOPDEV ]]; then
ddebug "losetup -d $LOOPDEV"
losetup -d $LOOPDEV
fi
rm -fr "$TESTDIR"
rm -f "$STATEFILE"
) || true
} }
# can be overridden in specific test # can be overridden in specific test
@ -1787,22 +1793,16 @@ do_test() {
--clean) --clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION" echo "TEST CLEANUP: $TEST_DESCRIPTION"
test_cleanup test_cleanup
rm -fr "$TESTDIR"
rm -f "$STATEFILE"
;; ;;
--all) --all)
ret=0 ret=0
echo -n "TEST: $TEST_DESCRIPTION "; echo -n "TEST: $TEST_DESCRIPTION "
( (
test_setup test_setup
test_setup_cleanup test_setup_cleanup
test_run test_run
ret=$?
test_cleanup
rm -fr "$TESTDIR"
rm -f "$STATEFILE"
exit $ret
) </dev/null >"$TESTLOG" 2>&1 || ret=$? ) </dev/null >"$TESTLOG" 2>&1 || ret=$?
test_cleanup
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
rm "$TESTLOG" rm "$TESTLOG"
echo "[OK]" echo "[OK]"