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

Improve tests for check-mysql #629

Merged
merged 9 commits into from Jul 29, 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
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
Comment on lines +9 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run sequentially because it's the easiest way to avoid port conflicts.

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
Copy link
Contributor Author

@susisu susisu Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which -s do not work on the CI environment.

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
Copy link
Contributor Author

@susisu susisu Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better than sleep, because sleep does not ensure that MySQL server has been started up.


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the following test requires uptime to be > 2, it might be unstable.


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
Comment on lines +83 to +84
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because starting replication takes some time, the following test was unstable.


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no test-*.sh to be executed directly anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[may][nit] or else: check-*/test*.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanted to allow each plugin to control how to run its tests, like avoiding port conflicts #629 (comment).
It's still possible if test.bash executes all of test*.sh, but I think only executing test.sh is easier to control.

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