Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin-elasticsearch] Fix the test for elasticsearch #966

Merged
merged 2 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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