Skip to content

Commit

Permalink
Merge pull request #966 from mackerelio/fix-test-elasticsearch
Browse files Browse the repository at this point in the history
[plugin-elasticsearch] Fix the test for elasticsearch
  • Loading branch information
lufia committed Dec 15, 2022
2 parents 359dae4 + 902904f commit 5010fd2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mackerel-plugin-elasticsearch/test.sh
Expand Up @@ -25,12 +25,13 @@ docker run -d \
-e "discovery.type=single-node" \
-e "ingest.geoip.downloader.enabled=false" \
elasticsearch:8.5.0
trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT
sleep 60
trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15

# to store previous value to calculate a diff of metrics
$plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error >/dev/null 2>&1
../tool/waituntil.bash -n 300 $plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error >/dev/null 2>&1

sleep 1

$plugin -scheme https -port $port -user=elastic -password $password -insecure -suppress-missing-error | graphite-metric-test -f rule.txt
status=$?

Expand Down
35 changes: 35 additions & 0 deletions tool/waituntil.bash
@@ -0,0 +1,35 @@
#!/bin/bash
# usage: waituntil [-n count] command [arg ...]

usage()
{
echo "usage: $(basename $0) [-n count] command [arg ...]" >&2
exit 2
}

count=0 # unlimited
while getopts :n: OPT
do
case "$OPT" in
:) usage ;;
n) count="$OPTARG" ;;
\?) usage ;;
esac
done
shift $((OPTIND - 1))
if (($# == 0))
then
usage
fi

i=0
while (($count == 0 || $i < $count))
do
if command "$@"
then
exit 0
fi
sleep 1
((i++))
done
exit 1

0 comments on commit 5010fd2

Please sign in to comment.