diff --git a/mackerel-plugin-elasticsearch/test.sh b/mackerel-plugin-elasticsearch/test.sh index 3957fc1dd..1c00ea85f 100755 --- a/mackerel-plugin-elasticsearch/test.sh +++ b/mackerel-plugin-elasticsearch/test.sh @@ -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=$? diff --git a/tool/waituntil.bash b/tool/waituntil.bash new file mode 100755 index 000000000..0b3f3ad57 --- /dev/null +++ b/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