Skip to content

Commit

Permalink
Merge pull request #629 from mackerelio/update-mysql-test
Browse files Browse the repository at this point in the history
Improve tests for check-mysql
  • Loading branch information
susisu committed Jul 29, 2022
2 parents 75a7300 + 391eeca commit a5efe13
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 28 deletions.
13 changes: 1 addition & 12 deletions check-mysql/test-tls.sh
Expand Up @@ -8,7 +8,6 @@ then
fi

cd "$(dirname "$0")" || exit
PATH=$(pwd):$PATH
plugin=$(basename "$(pwd)")
if ! which "$plugin" >/dev/null
then
Expand All @@ -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"

Expand Down
11 changes: 11 additions & 0 deletions 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
6 changes: 4 additions & 2 deletions check-mysql/test_57/docker-compose.yml
Expand Up @@ -3,6 +3,7 @@ version: '3.1'
services:
primary:
image: mysql:5.7.8
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: mysql
command:
Expand All @@ -17,8 +18,7 @@ services:

replica:
image: mysql:5.7.8
ports:
- 23306:3306
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: mysql
command:
Expand All @@ -27,3 +27,5 @@ services:
- --bind_address=0.0.0.0
- --log_bin=bin.log
- --read_only=1
ports:
- 23306:3306
14 changes: 9 additions & 5 deletions check-mysql/test_57/test.sh
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions check-mysql/test_8/docker-compose.yml
Expand Up @@ -3,6 +3,7 @@ version: '3.1'
services:
primary:
image: mysql:8.0.23
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: mysql
command:
Expand All @@ -17,8 +18,7 @@ services:

replica:
image: mysql:8.0.23
ports:
- 23306:3306
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: mysql
command:
Expand All @@ -27,3 +27,5 @@ services:
- --bind_address=0.0.0.0
- --log_bin=bin.log
- --read_only=1
ports:
- 23306:3306
14 changes: 9 additions & 5 deletions check-mysql/test_8/test.sh
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions 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")
Expand All @@ -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=$!
Expand Down

0 comments on commit a5efe13

Please sign in to comment.