summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaushal M <kaushal@redhat.com>2012-12-04 12:44:22 +0530
committerAnand Avati <avati@redhat.com>2012-12-04 00:18:00 -0800
commitc6bb978f93e7e2974b0c8568af09b72bfbc35987 (patch)
tree457fdf4ab89c6268e01defb738c10ca28c5a23cc
parentbb5382208696196aead94c011b3f9fa13a04da68 (diff)
tests: Introduce new test primitive EXPECT_WITHIN
Introduces a new test primitive EXPECT_WITHIN with syntax, EXPECT_WITHIN <timeout in seconds> <expected output> <command> which runs the given command every second and compares its output with the expected output, till the timeout occurs. Change-Id: I91c6de157e5d33fffafe532ceba84e2a9223356f BUG: 857330 Signed-off-by: Kaushal M <kaushal@redhat.com> Reviewed-on: http://review.gluster.org/4263 Reviewed-by: Anand Avati <avati@redhat.com> Tested-by: Anand Avati <avati@redhat.com>
-rw-r--r--tests/include.rc37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/include.rc b/tests/include.rc
index 585a4e2c885..cfa9390aaef 100644
--- a/tests/include.rc
+++ b/tests/include.rc
@@ -13,7 +13,7 @@ mkdir -p $B0;
mkdir -p $M0 $M1;
mkdir -p $N0 $N1;
-testcnt=`egrep '^[ \t]*(EXPECT|TEST)' $0 | wc -l`;
+testcnt=`egrep '^[ \t]*(EXPECT|TEST|EXPECT_WITHIN)' $0 | wc -l`;
echo 1..$testcnt
t=1
@@ -74,6 +74,40 @@ function _TEST()
test_footer;
}
+function _EXPECT_WITHIN()
+{
+ TESTLINE=$1
+ shift;
+
+ local timeout=$1
+ shift;
+
+ test_header "$@"
+
+ e=$1;
+ shift;
+
+ local endtime=$(( ${timeout}+`date +%s` ))
+
+ local success=0
+ while [ `date +%s` -lt $endtime ]; do
+ "$@" | tail -1 | egrep -q "^${e}\$"
+ if [ $? -eq 0 ]; then
+ success=1;
+ break;
+ fi
+ sleep 1;
+ done
+
+ if [ $success -eq 1 ]; then
+ true;
+ else
+ false;
+ fi
+
+ test_footer;
+}
+
function cleanup()
{
@@ -90,4 +124,5 @@ function cleanup()
alias EXPECT='_EXPECT $LINENO'
alias TEST='_TEST $LINENO'
+alias EXPECT_WITHIN='_EXPECT_WITHIN $LINENO'
shopt -s expand_aliases