Commit 6913e19b authored by zauberstuhl's avatar zauberstuhl

Add timeout parameter for wait_for function

parent 9136232a
......@@ -67,7 +67,7 @@ function send_type() {
function cmd() {
query "g1" "select count(*) from posts where public = true;"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
......@@ -84,7 +84,7 @@ function send_type() {
function cmd() {
query "g1" "select count(*) from comments where guid = '$guid';"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
......@@ -100,7 +100,7 @@ function send_type() {
function cmd() {
query "g1" "select count(*) from likes where guid = '$guid';"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
......
......@@ -100,7 +100,7 @@ function send_type() {
query "d1" "select count(*) from posts
where guid = '$guid' and public = $public;"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
......@@ -117,7 +117,7 @@ function send_type() {
query "d1" "select count(*) from comments
where guid = '$guid';"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
......@@ -134,7 +134,7 @@ function send_type() {
query "d1" "select count(*) from likes
where guid = '$guid';"
}
code=$(wait_for cmd "1")
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
......
......@@ -55,16 +55,20 @@ function remove_app() {
docker rm $1
}
# wait_for "docker logs g1" "Listening on"
# wait_for "docker logs g1" "Listening on" 120
function wait_for() {
timeout=500
if [[ $3 =~ '^[0-9]+$' ]] ; then
timeout=$3
fi
command -v $1 >/dev/null
if [ "$?" -ne 0 ]; then echo 1; return; fi
while true; do
$1 |grep -m 1 "$2" >/dev/null
if [ "$?" -eq 0 ]; then echo 0; break; fi
if [ "$i" -eq 250 ]; then echo 1; break; fi
if [ "$i" -eq $timeout ]; then echo 1; break; fi
((i++))
sleep 2
sleep 1
done
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment