Skip to content

Commit

Permalink
test: 增加 mysql8 e2e 测试
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyangxixian committed Jul 10, 2024
1 parent 813cd5e commit f4d7c20
Show file tree
Hide file tree
Showing 31 changed files with 625 additions and 65 deletions.
14 changes: 12 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ stages:
- scan
- check
- unittest
- build
- e2e-test
- e2e-test-mysql8
- pre-release
- build
- release

.fusion-cli: &fusion-cli
Expand Down Expand Up @@ -85,13 +86,22 @@ build_branch:
stage: build
script:
- make build
only:
- staging
- tags

e2e_test:
stage: e2e-test
image: micr.cloud.mioffice.cn/devdba/centos-mysql-golang:v1.0.2
image: micr.cloud.mioffice.cn/devdba/centos-mysql-golang:v1.0.3
script:
- make e2e-test

e2e_test_mysql8:
stage: e2e-test-mysql8
image: micr.cloud.mioffice.cn/devdba/centos-mysql8-golang:v1.0.1
script:
- make e2e-test-mysql8

upload_fds:
stage: pre-release
only:
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ test:

e2e-test: gaea gaea-cc
cp bin/gaea bin/gaea-cc tests/e2e/cmd/
./hack/e2e.sh
ginkgo --v --progress --trace --flake-attempts=1 ./tests/e2e/
./hack/e2e-mysql5.sh
./hack/ginkgo-run-mysql5.sh

e2e-test-mysql8: gaea gaea-cc
cp bin/gaea bin/gaea-cc tests/e2e/cmd/
./hack/e2e-mysql8.sh
./hack/ginkgo-run-mysql8.sh

integrate_test:
go test -timeout 30m -coverprofile=.integrate_coverage.out ./... -run ^TestIntegration$
Expand Down
14 changes: 7 additions & 7 deletions hack/e2e.sh → hack/e2e-mysql5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function check_mysql_dir() {
}

if [ $(check_pid "etcd") -eq 0 ];then
etcd --data-dir bin/etcd 2>&1 1>>bin/etcd.log &
etcd --data-dir bin/etcd 2>&1 &>>bin/etcd.log &
fi

# Start 2 Mysql Cluster
# Cluster-1: 3319(master), 3329(slave), 3339(slave)
# Prepare Cluster-1 for master
if [ $(check_mysql_dir "3319") -eq 0 ];then
cp ./tests/docker/my3319.cnf /data/etc/my3319.cnf
cp ./tests/docker/mysql5/my3319.cnf /data/etc/my3319.cnf
mysqld --defaults-file=/data/etc/my3319.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3319.cnf --user=work &
sleep 3
Expand All @@ -40,7 +40,7 @@ if [ $(check_mysql_dir "3319") -eq 0 ];then
GRANT REPLICATION SLAVE, REPLICATION CLIENT on *.* to 'mysqlsync'@'%' IDENTIFIED BY 'mysqlsync';
GRANT ALL ON *.* TO 'superroot'@'%' IDENTIFIED BY 'superroot' WITH GRANT OPTION;
GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'gaea_backend_user'@'%' IDENTIFIED BY 'gaea_backend_pass';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gaea_backend_user'@'%' IDENTIFIED BY 'gaea_backend_pass';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gaea_backend_user'@'%' IDENTIFIED BY 'gaea_backend_pass';
EOF
else
if [ $(check_pid "my3319") -eq 0 ];then
Expand All @@ -50,7 +50,7 @@ fi

# Prepare Cluster-1 slave 1
if [ $(check_mysql_dir "3329") -eq 0 ];then
cp ./tests/docker/my3329.cnf /data/etc/my3329.cnf
cp ./tests/docker/mysql5/my3329.cnf /data/etc/my3329.cnf
mysqld --defaults-file=/data/etc/my3329.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3329.cnf --user=work &
sleep 3
Expand All @@ -67,7 +67,7 @@ fi

# Prepare Cluster-1 slave 2
if [ $(check_mysql_dir "3339") -eq 0 ];then
cp ./tests/docker/my3339.cnf /data/etc/my3339.cnf
cp ./tests/docker/mysql5/my3339.cnf /data/etc/my3339.cnf
mysqld --defaults-file=/data/etc/my3339.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3339.cnf --user=work &
sleep 3
Expand All @@ -84,7 +84,7 @@ fi

# Cluster-2: 3379(master)
if [ $(check_mysql_dir "3379") -eq 0 ];then
cp ./tests/docker/my3379.cnf /data/etc/my3379.cnf
cp ./tests/docker/mysql5/my3379.cnf /data/etc/my3379.cnf
mysqld --defaults-file=/data/etc/my3379.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3379.cnf --user=work &
sleep 3
Expand All @@ -103,7 +103,7 @@ fi

# Cluster-3: 3349(master)
if [ $(check_mysql_dir "3349") -eq 0 ];then
cp ./tests/docker/my3349.cnf /data/etc/my3349.cnf
cp ./tests/docker/mysql5/my3349.cnf /data/etc/my3349.cnf
mysqld --defaults-file=/data/etc/my3349.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3349.cnf --user=work &
sleep 3
Expand Down
130 changes: 130 additions & 0 deletions hack/e2e-mysql8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash

set -euo pipefail

# prepare env
if [ $(ls $HOME/go/bin/|grep ginkgo|wc -l) -eq 0 ];then
go install github.com/onsi/ginkgo/v2/[email protected]
fi

# prepare etcd env
# shellcheck disable=SC2069

function check_pid() {
value=$1
pid_num=$(ps aux|grep "$value"|grep -v 'grep'|wc -l)
echo $pid_num
}

function check_mysql_dir() {
value=$1
pid_num=$(ps aux|grep etcd|grep -v 'grep'|wc -l)
dir_num=$(ls /data/mysql/|grep "$value"|wc -l)
echo $dir_num
}

if [ $(check_pid "etcd") -eq 0 ];then
etcd --data-dir bin/etcd 2>&1 &>>bin/etcd.log &
fi

# Start 2 Mysql Cluster
# Cluster-1: 3319(master), 3329(slave), 3339(slave)
# Prepare Cluster-1 for master
if [ $(check_mysql_dir "3319") -eq 0 ];then
cp ./tests/docker/mysql8/my3319.cnf /data/etc/my3319.cnf
mysqld --defaults-file=/data/etc/my3319.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3319.cnf --user=work &
sleep 3
mysql -h127.0.0.1 -P3319 -uroot -S/data/tmp/mysql3319.sock <<EOF
reset master;
CREATE USER 'mysqlsync'@'%' IDENTIFIED with mysql_native_password BY 'mysqlsync';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'mysqlsync'@'%';
CREATE USER 'superroot'@'%' IDENTIFIED with mysql_native_password BY 'superroot';
GRANT ALL PRIVILEGES ON *.* TO 'superroot'@'%' WITH GRANT OPTION;
CREATE USER 'gaea_backend_user'@'%' IDENTIFIED with mysql_native_password BY 'gaea_backend_pass';
GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'gaea_backend_user'@'%';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gaea_backend_user'@'%';
EOF
else
if [ $(check_pid "my3319") -eq 0 ];then
mysqld --defaults-file=/data/etc/my3319.cnf --user=work &
fi
fi

# Prepare Cluster-1 slave 1
if [ $(check_mysql_dir "3329") -eq 0 ];then
cp ./tests/docker/mysql8/my3329.cnf /data/etc/my3329.cnf
mysqld --defaults-file=/data/etc/my3329.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3329.cnf --user=work &
sleep 3
mysql -h127.0.0.1 -P3329 -uroot -S/data/tmp/mysql3329.sock <<EOF
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=3319, MASTER_USER='mysqlsync', MASTER_PASSWORD='mysqlsync', MASTER_AUTO_POSITION=1;
START SLAVE;
DO SLEEP(1);
EOF
else
if [ $(check_pid "my3329") -eq 0 ];then
mysqld --defaults-file=/data/etc/my3329.cnf --user=work &
fi
fi

# Prepare Cluster-1 slave 2
if [ $(check_mysql_dir "3339") -eq 0 ];then
cp ./tests/docker/mysql8/my3339.cnf /data/etc/my3339.cnf
mysqld --defaults-file=/data/etc/my3339.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3339.cnf --user=work &
sleep 3
mysql -h127.0.0.1 -P3339 -uroot -S/data/tmp/mysql3339.sock <<EOF
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=3319, MASTER_USER='mysqlsync', MASTER_PASSWORD='mysqlsync', MASTER_AUTO_POSITION=1;
START SLAVE;
DO SLEEP(1);
EOF
else
if [ $(check_pid "my3339") -eq 0 ];then
mysqld --defaults-file=/data/etc/my3339.cnf --user=work &
fi
fi

# Cluster-2: 3379(master)
if [ $(check_mysql_dir "3379") -eq 0 ];then
cp ./tests/docker/mysql8/my3379.cnf /data/etc/my3379.cnf
mysqld --defaults-file=/data/etc/my3379.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3379.cnf --user=work &
sleep 3
mysql -h127.0.0.1 -P3379 -uroot -S/data/tmp/mysql3379.sock <<EOF
reset master;
CREATE USER 'mysqlsync'@'%' IDENTIFIED with mysql_native_password BY 'mysqlsync';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'mysqlsync'@'%';
CREATE USER 'superroot'@'%' IDENTIFIED with mysql_native_password BY 'superroot';
GRANT ALL PRIVILEGES ON *.* TO 'superroot'@'%' WITH GRANT OPTION;
CREATE USER 'gaea_backend_user'@'%' IDENTIFIED with mysql_native_password BY 'gaea_backend_pass';
GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'gaea_backend_user'@'%';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gaea_backend_user'@'%';
EOF
else
if [ $(check_pid "my3379") -eq 0 ];then
mysqld --defaults-file=/data/etc/my3379.cnf --user=work &
fi
fi

# Cluster-3: 3349(master)
if [ $(check_mysql_dir "3349") -eq 0 ];then
cp ./tests/docker/mysql8/my3349.cnf /data/etc/my3349.cnf
mysqld --defaults-file=/data/etc/my3349.cnf --user=work --initialize-insecure
mysqld --defaults-file=/data/etc/my3349.cnf --user=work &
sleep 3
mysql -h127.0.0.1 -P3349 -uroot -S/data/tmp/mysql3349.sock <<EOF
reset master;
CREATE USER 'mysqlsync'@'%' IDENTIFIED with mysql_native_password BY 'mysqlsync';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'mysqlsync'@'%';
CREATE USER 'superroot'@'%' IDENTIFIED with mysql_native_password BY 'superroot';
GRANT ALL PRIVILEGES ON *.* TO 'superroot'@'%' WITH GRANT OPTION;
CREATE USER 'gaea_backend_user'@'%' IDENTIFIED with mysql_native_password BY 'gaea_backend_pass';
GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'gaea_backend_user'@'%';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gaea_backend_user'@'%';
EOF
else
if [ $(check_pid "my3349") -eq 0 ];then
mysqld --defaults-file=/data/etc/my3349.cnf --user=work &
fi
fi
2 changes: 2 additions & 0 deletions hack/ginkgo-run-mysql5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
ginkgo --v --progress --trace --flake-attempts=1 --skip "^.*only mysql8:.*$" ./tests/e2e/
2 changes: 2 additions & 0 deletions hack/ginkgo-run-mysql8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
ginkgo --v --progress --trace --flake-attempts=1 --skip '^.*only mysql5:.*$' --skip '^.*shard join support test in.*$' --skip 'test dml set variables' --skip 'simple sql test' --skip='Unshard DML Support Test' ./tests/e2e/
1 change: 1 addition & 0 deletions proxy/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (cc *Session) clientConnectionReachLimit() (bool, int) {
return false, 0
}

// 并发情况下,这边判断有问题,会检测不准,修改成原子操作,对建立连接性能有影响,暂不处理
var v = int(current.(*uber_atomic.Int32).Load())
if v >= cc.getNamespace().maxClientConnections {
return true, v
Expand Down
36 changes: 0 additions & 36 deletions tests/docker/install_dependencies.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tests/docker/Dockerfile → tests/docker/mysql5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ FROM centos:centos7
# Install dependencies
COPY install_dependencies.sh /dist/install_dependencies.sh
RUN /dist/install_dependencies.sh
ENV PATH /usr/local/go/bin:$PATH
ENV PATH /usr/local/go/bin:/root/go/bin/:$PATH
84 changes: 84 additions & 0 deletions tests/docker/mysql5/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

set -euo pipefail

# 更新源
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

# install mysql
yum install -y wget perl net-tools etcd curl libaio libaio-devel numactl make git gcc
yum install -y glibc
yum update -y
# modify timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

cd /dist
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.25-28/binary/redhat/7/x86_64/Percona-Server-server-57-5.7.25-28.1.el7.x86_64.rpm
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.25-28/binary/redhat/7/x86_64/Percona-Server-shared-compat-57-5.7.25-28.1.el7.x86_64.rpm
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.25-28/binary/redhat/7/x86_64/Percona-Server-shared-57-5.7.25-28.1.el7.x86_64.rpm
wget https://downloads.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.25-28/binary/redhat/7/x86_64/Percona-Server-client-57-5.7.25-28.1.el7.x86_64.rpm

rpm -ivh Percona-Server-server-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-shared-compat-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-shared-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-client-57-5.7.25-28.1.el7.x86_64.rpm

rm -rf Percona-Server-server-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-shared-compat-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-shared-57-5.7.25-28.1.el7.x86_64.rpm \
Percona-Server-client-57-5.7.25-28.1.el7.x86_64.rpm

groupadd -r --gid 2000 work
useradd -r -g work --uid 1000 work
mkdir -p /data/mysql /data/tmp /data/etc
chown -R work:work /data

# install golang
wget https://go.dev/dl/go1.16.15.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.15.linux-amd64.tar.gz

# 提前安装一些依赖库,跑 CI 的时间就可以不用拉了,减少测试用例时间
/usr/local/go/bin/go install github.com/onsi/ginkgo/v2/[email protected]
/usr/local/go/bin/go mod download github.com/shirou/[email protected]+incompatible
/usr/local/go/bin/go mod download go.uber.org/[email protected]
/usr/local/go/bin/go mod download github.com/golang/[email protected]
/usr/local/go/bin/go mod download github.com/gin-contrib/[email protected]
/usr/local/go/bin/go mod download github.com/gin-gonic/[email protected]
/usr/local/go/bin/go mod download github.com/pingcap/[email protected]
/usr/local/go/bin/go mod download github.com/shopspring/[email protected]
/usr/local/go/bin/go mod download github.com/hashicorp/[email protected]
/usr/local/go/bin/go mod download github.com/go-ini/[email protected]
/usr/local/go/bin/go mod download github.com/pingcap/[email protected]
/usr/local/go/bin/go mod download github.com/coreos/[email protected]+incompatible
/usr/local/go/bin/go mod download github.com/emirpasic/[email protected]
/usr/local/go/bin/go mod download github.com/prometheus/[email protected]
/usr/local/go/bin/go mod download github.com/cznic/[email protected]
/usr/local/go/bin/go mod download github.com/prometheus/[email protected]
/usr/local/go/bin/go mod download github.com/prometheus/[email protected]
/usr/local/go/bin/go mod download github.com/beorn7/[email protected]
/usr/local/go/bin/go mod download github.com/golang/[email protected]
/usr/local/go/bin/go mod download github.com/prometheus/[email protected]
/usr/local/go/bin/go mod download github.com/remyoudompheng/[email protected]
/usr/local/go/bin/go mod download github.com/mattn/[email protected]
/usr/local/go/bin/go mod download github.com/gin-contrib/[email protected]
/usr/local/go/bin/go mod download gopkg.in/[email protected]
/usr/local/go/bin/go mod download github.com/ugorji/[email protected]
/usr/local/go/bin/go mod download github.com/go-playground/validator/[email protected]
/usr/local/go/bin/go mod download golang.org/x/[email protected]
/usr/local/go/bin/go mod download github.com/ugorji/go/[email protected]
/usr/local/go/bin/go mod download google.golang.org/[email protected]
/usr/local/go/bin/go mod download github.com/matttproud/[email protected]
/usr/local/go/bin/go mod download golang.org/x/[email protected]
/usr/local/go/bin/go mod download golang.org/x/[email protected]
/usr/local/go/bin/go mod download github.com/leodido/[email protected]
/usr/local/go/bin/go mod download github.com/go-playground/[email protected]
/usr/local/go/bin/go mod download github.com/go-playground/[email protected]
/usr/local/go/bin/go mod download github.com/modern-go/[email protected]
/usr/local/go/bin/go mod download github.com/json-iterator/[email protected]
/usr/local/go/bin/go mod download github.com/coreos/[email protected]
/usr/local/go/bin/go mod download google.golang.org/[email protected]
/usr/local/go/bin/go mod download github.com/gogo/[email protected]
/usr/local/go/bin/go mod download golang.org/x/[email protected]
/usr/local/go/bin/go mod download github.com/modern-go/[email protected]
/usr/local/go/bin/go mod download google.golang.org/[email protected]
4 changes: 3 additions & 1 deletion tests/docker/my3319.cnf → tests/docker/mysql5/my3319.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ binlog_format = row
log_bin_trust_function_creators = 1
skip_slave_start

general-log = 0
general-log = 1
general_log_file = /data/mysql/data3319/general.log

log_warnings
log_error = /data/mysql/data3319/log_error.err
max_connections = 4096
max_user_connections = 4096
Loading

0 comments on commit f4d7c20

Please sign in to comment.