summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/basic/ec/ec.t8
-rw-r--r--tests/bugs/disperse/bug-1161621.t5
-rw-r--r--tests/features/recon.t3
-rw-r--r--tests/snapshot.rc5
-rw-r--r--tests/traps.rc22
5 files changed, 34 insertions, 9 deletions
diff --git a/tests/basic/ec/ec.t b/tests/basic/ec/ec.t
index b07006545b9..f98f2110e8f 100644
--- a/tests/basic/ec/ec.t
+++ b/tests/basic/ec/ec.t
@@ -1,5 +1,6 @@
#!/bin/bash
+. $(dirname $0)/../../traps.rc
. $(dirname $0)/../../include.rc
. $(dirname $0)/../../volume.rc
@@ -155,7 +156,7 @@ function check_perm_file {
cleanup
TEST useradd -o -M -u ${TEST_UID} ${TEST_USER}
-trap "userdel --force ${TEST_USER}" EXIT
+push_trapfunc "userdel --force ${TEST_USER}"
TEST glusterd
TEST pidof glusterd
@@ -177,7 +178,7 @@ EXPECT_WITHIN $CHILD_UP_TIMEOUT "10" ec_child_up_count $V0 0
# Create local files for comparisons etc.
tmpdir=$(mktemp -d -t ${0##*/}.XXXXXX)
-trap "rm -rf $tmpdir" EXIT
+push_trapfunc "rm -rf $tmpdir"
TEST create_file $tmpdir/create-write 10
TEST create_file $tmpdir/truncate 10
@@ -255,7 +256,4 @@ EXPECT_WITHIN $HEAL_TIMEOUT "Y" check_setxattr $B0/${V0}{0..9}
EXPECT_WITHIN $HEAL_TIMEOUT "Y" check_removexattr $B0/${V0}{0..9}
EXPECT_WITHIN $HEAL_TIMEOUT "Y" check_perm_file $B0/${V0}{0..9}
-TEST rm -rf $tmpdir
-TEST userdel --force ${TEST_USER}
-
cleanup
diff --git a/tests/bugs/disperse/bug-1161621.t b/tests/bugs/disperse/bug-1161621.t
index 56d4cede090..84361e440dc 100644
--- a/tests/bugs/disperse/bug-1161621.t
+++ b/tests/bugs/disperse/bug-1161621.t
@@ -1,5 +1,6 @@
#!/bin/bash
+. $(dirname $0)/../../traps.rc
. $(dirname $0)/../../include.rc
. $(dirname $0)/../../volume.rc
@@ -16,7 +17,7 @@ TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M1
EXPECT_WITHIN $CHILD_UP_TIMEOUT "5" ec_child_up_count $V0 0
tmpdir=$(mktemp -d -t ${0##*/}.XXXXXX)
-trap "rm -rf $tmpdir" EXIT
+push_trapfunc "rm -rf $tmpdir"
TEST dd if=/dev/urandom of=$tmpdir/file bs=1234 count=20
cs=$(sha1sum $tmpdir/file | awk '{ print $1 }')
@@ -38,6 +39,4 @@ wait
EXPECT "24680000" stat -c "%s" $M0/shared
EXPECT "$cs" echo $(sha1sum $M0/shared | awk '{ print $1 }')
-TEST rm -rf $tmpdir
-
cleanup
diff --git a/tests/features/recon.t b/tests/features/recon.t
index 7dda2a680e8..9989f243380 100644
--- a/tests/features/recon.t
+++ b/tests/features/recon.t
@@ -1,5 +1,6 @@
#!/bin/bash
+. $(dirname $0)/../traps.rc
. $(dirname $0)/../include.rc
. $(dirname $0)/../volume.rc
@@ -11,7 +12,7 @@ FDL_META_FILE=${log_base}/${log_id}-meta-1.jnl
FDL_DATA_FILE=${log_base}/${log_id}-data-1.jnl
tmpdir=$(mktemp -d -t ${0##*/}.XXXXXX)
-trap "rm -rf $tmpdir" EXIT
+push_trapfunc "rm -rf $tmpdir"
write_file () {
echo "peekaboo" > $1
diff --git a/tests/snapshot.rc b/tests/snapshot.rc
index cca1f4d4988..f6da514f826 100644
--- a/tests/snapshot.rc
+++ b/tests/snapshot.rc
@@ -94,6 +94,11 @@ function cleanup_lvm() {
return 0
}
+# Find out how this file was sourced, source traps.rc the same way, and use
+# push_trapfunc to make sure cleanup_lvm gets called before we exit.
+. $(dirname ${BASH_SOURCE[0]})/traps.rc
+push_trapfunc cleanup_lvm
+
########################################################
# Private Functions
########################################################
diff --git a/tests/traps.rc b/tests/traps.rc
new file mode 100644
index 00000000000..f011960c97e
--- /dev/null
+++ b/tests/traps.rc
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Make sure this only gets included/executed once. Unfortunately, bash doesn't
+# usually distinguish between values that are unset and values that are null.
+# To work around that, we declare TRAPFUNCS to be a one-element array right at
+# the start, but that one element is : which is defined to do nothing.
+
+if [ ${#TRAPFUNCS[@]} = 0 ]; then
+ TRAPFUNCS=(:)
+
+ push_trapfunc () {
+ TRAPFUNCS[${#TRAPFUNCS[@]}]="$@"
+ }
+
+ execute_trapfuncs () {
+ for i in "${TRAPFUNCS[@]}"; do
+ $i
+ done
+ }
+
+ trap execute_trapfuncs EXIT
+fi