diff --git a/check-mysql/test-tls.sh b/check-mysql/test-tls.sh index 0455ca36..efc74ed0 100755 --- a/check-mysql/test-tls.sh +++ b/check-mysql/test-tls.sh @@ -8,7 +8,6 @@ then fi cd "$(dirname "$0")" || exit -PATH=$(pwd):$PATH plugin=$(basename "$(pwd)") if ! which "$plugin" >/dev/null then @@ -27,17 +26,7 @@ docker run -d \ -e "MYSQL_ROOT_PASSWORD=$password" "$image" trap 'docker stop test-$plugin; docker rm test-$plugin; rm $cacert; exit 1' 1 2 3 15 -# wait until bootstrap mysqld.. -for i in $(seq 10) -do - echo "Connecting $i..." - if $plugin connection --port $port --password $password >/dev/null 2>&1 - then - break - fi - sleep 3 -done -sleep 1 +USER=root PASSWORD=$password PORT=$port ./wait.sh docker cp "test-$plugin:/var/lib/mysql/ca.pem" "$cacert" diff --git a/check-mysql/test.sh b/check-mysql/test.sh new file mode 100755 index 00000000..ae01cadd --- /dev/null +++ b/check-mysql/test.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -ex + +cd "$(dirname "$0")" + +export PATH=$(pwd):$PATH + +./test_57/test.sh +./test_8/test.sh +./test-tls.sh diff --git a/check-mysql/test_57/docker-compose.yml b/check-mysql/test_57/docker-compose.yml index 1c3a1ea0..8dee718b 100644 --- a/check-mysql/test_57/docker-compose.yml +++ b/check-mysql/test_57/docker-compose.yml @@ -3,6 +3,7 @@ version: '3.1' services: primary: image: mysql:5.7.8 + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: mysql command: @@ -17,8 +18,7 @@ services: replica: image: mysql:5.7.8 - ports: - - 23306:3306 + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: mysql command: @@ -27,3 +27,5 @@ services: - --bind_address=0.0.0.0 - --log_bin=bin.log - --read_only=1 + ports: + - 23306:3306 diff --git a/check-mysql/test_57/test.sh b/check-mysql/test_57/test.sh index a8fc0b5a..381721b4 100755 --- a/check-mysql/test_57/test.sh +++ b/check-mysql/test_57/test.sh @@ -12,13 +12,12 @@ fi cd $(dirname $0) plugin=$(basename $(realpath ../)) -if ! which -s $plugin +if ! which "$plugin" >/dev/null then echo "$prog: $plugin is not installed" >&2 exit 2 fi -sleep_time=30 user=root password=mysql primary_port=13306 @@ -30,16 +29,18 @@ if $plugin connection --host=127.0.0.1 --port=$primary_port --user=$user --passw fi docker-compose up -d - trap 'docker-compose down --rmi local -v' EXIT -sleep $sleep_time + +USER=$user PASSWORD=$password PORT=$primary_port ../wait.sh if ! $plugin connection --host=127.0.0.1 --port=$primary_port --user=$user --password=$password; then echo 'FAIL: connection should be OK' exit 1 fi -if ! $plugin uptime --host=127.0.0.1 --port=$primary_port --user=$user --password=$password --critical=2 --warning=1; then +sleep 2 + +if ! $plugin uptime --host=127.0.0.1 --port=$primary_port --user=$user --password=$password --critical=1 --warning=2; then echo 'FAIL: uptime should be OK' exit 1 fi @@ -79,6 +80,9 @@ mysql -u$user -p$password --host 127.0.0.1 --port=$replica_port -e """ START SLAVE USER='repl' PASSWORD='repl'; """ +# starting replication may take a while +sleep 1 + if ! $plugin replication --host=127.0.0.1 --port=$replica_port --user=$user --password=$password; then echo 'FAIL: replication of replica server should be started' exit 1 diff --git a/check-mysql/test_8/docker-compose.yml b/check-mysql/test_8/docker-compose.yml index d077cb1b..d827aea9 100644 --- a/check-mysql/test_8/docker-compose.yml +++ b/check-mysql/test_8/docker-compose.yml @@ -3,6 +3,7 @@ version: '3.1' services: primary: image: mysql:8.0.23 + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: mysql command: @@ -17,8 +18,7 @@ services: replica: image: mysql:8.0.23 - ports: - - 23306:3306 + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: mysql command: @@ -27,3 +27,5 @@ services: - --bind_address=0.0.0.0 - --log_bin=bin.log - --read_only=1 + ports: + - 23306:3306 diff --git a/check-mysql/test_8/test.sh b/check-mysql/test_8/test.sh index 07766a8c..2a883366 100755 --- a/check-mysql/test_8/test.sh +++ b/check-mysql/test_8/test.sh @@ -12,13 +12,12 @@ fi cd $(dirname $0) plugin=$(basename $(realpath ../)) -if ! which -s $plugin +if ! which "$plugin" >/dev/null then echo "$prog: $plugin is not installed" >&2 exit 2 fi -sleep_time=35 user=root password=mysql primary_port=13306 @@ -30,16 +29,18 @@ if $plugin connection --host=127.0.0.1 --port=$primary_port --user=$user --passw fi docker-compose up -d - trap 'docker-compose down --rmi local -v' EXIT -sleep $sleep_time + +USER=$user PASSWORD=$password PORT=$primary_port ../wait.sh if ! $plugin connection --host=127.0.0.1 --port=$primary_port --user=$user --password=$password; then echo 'FAIL: connection should be OK' exit 1 fi -if ! $plugin uptime --host=127.0.0.1 --port=$primary_port --user=$user --password=$password --critical=2 --warning=1; then +sleep 2 + +if ! $plugin uptime --host=127.0.0.1 --port=$primary_port --user=$user --password=$password --critical=1 --warning=2; then echo 'FAIL: uptime should be OK' exit 1 fi @@ -79,6 +80,9 @@ mysql -u$user -p$password --host 127.0.0.1 --port=$replica_port -e """ START REPLICA USER='repl' PASSWORD='repl'; """ +# starting replication may take a while +sleep 1 + if ! $plugin replication --host=127.0.0.1 --port=$replica_port --user=$user --password=$password; then echo 'FAIL: replication of replica server should be started' exit 1 diff --git a/check-mysql/wait.sh b/check-mysql/wait.sh new file mode 100755 index 00000000..dcdb2837 --- /dev/null +++ b/check-mysql/wait.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# wait until bootstrap mysqld.. (max = 60s) +for i in $(seq 20) +do + echo "Connecting $i..." + if mysql -u"$USER" -p"$PASSWORD" --host=127.0.0.1 --port="$PORT" -e"select 1" >/dev/null; then + break + fi + sleep 3 +done +sleep 1 diff --git a/test.bash b/test.bash index 15159859..cd506e24 100755 --- a/test.bash +++ b/test.bash @@ -1,7 +1,7 @@ #!/bin/bash # prepare tests -for f in check-*/test.sh check-*/test-*.sh +for f in check-*/test.sh do dir=$(dirname "$f") name=$(basename "$dir") @@ -11,7 +11,7 @@ done # run tests declare -A plugins=() declare -a pids=() -for f in check-*/test.sh check-*/test-*.sh +for f in check-*/test.sh do ./"$f" & pid=$!