Skip to content

Commit d525053

Browse files
authored
Allow to run all tests with mysql:8 (#765)
allow running all tests with mysql:8
1 parent 4dfcc8c commit d525053

File tree

7 files changed

+43
-20
lines changed

7 files changed

+43
-20
lines changed

.github/workflows/ci.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ jobs:
66
strategy:
77
matrix:
88
go: [ 1.19, 1.18, 1.17, 1.16 ]
9-
name: Tests Go ${{ matrix.go }}
10-
runs-on: ubuntu-18.04
9+
os: [ ubuntu-18.04, ubuntu-20.04 ]
10+
name: Tests Go ${{ matrix.go }} # This name is used in main branch protection rules
11+
runs-on: ${{ matrix.os }}
1112

1213
steps:
1314
- name: Setup MySQL
@@ -17,7 +18,11 @@ jobs:
1718
1819
echo -e '[mysqld]\nserver-id=1\nlog-bin=mysql\nbinlog-format=row\ngtid-mode=ON\nenforce_gtid_consistency=ON\n' | sudo tee /etc/mysql/conf.d/replication.cnf
1920
sudo service mysql start
20-
sudo mysql -h 127.0.0.1 -uroot -proot -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password'; FLUSH PRIVILEGES;"
21+
22+
# apply this for mysql5 & mysql8 compatibility
23+
sudo mysql -h 127.0.0.1 -uroot -proot -e "DROP USER IF EXISTS 'mysql.infoschema'@'localhost'; CREATE USER IF NOT EXISTS 'mysql.infoschema'@'localhost' IDENTIFIED BY ''; GRANT SELECT ON *.* TO 'mysql.infoschema'@'localhost';"
24+
25+
sudo mysql -h 127.0.0.1 -uroot -proot -e "use mysql; update user set authentication_string=null where User='root'; update user set plugin='mysql_native_password'; FLUSH PRIVILEGES;"
2126
# create ssl/rsa files for mysql ssl support
2227
sudo mysql_ssl_rsa_setup --uid=mysql
2328
mysql -e "CREATE DATABASE IF NOT EXISTS test;" -uroot

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ build:
1111
test:
1212
go test --race -timeout 2m ./...
1313

14+
MYSQL_VERSION ?= 5.7
1415
test-local:
1516
docker run --rm -d --network=host --name go-mysql-server \
1617
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
1718
-e MYSQL_DATABASE=test \
1819
-v $${PWD}/docker/resources/replication.cnf:/etc/mysql/conf.d/replication.cnf \
19-
mysql:5.7
20+
mysql:$(MYSQL_VERSION)
2021
docker/resources/waitfor.sh 127.0.0.1 3306 \
2122
&& go test -race -v -timeout 2m ./... -gocheck.v
2223
docker stop go-mysql-server

client/auth.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func (c *Conn) readInitialHandshake() error {
4343

4444
// skip mysql version
4545
// mysql version end with 0x00
46-
pos := 1 + bytes.IndexByte(data[1:], 0x00) + 1
46+
version := data[1 : bytes.IndexByte(data[1:], 0x00)+1]
47+
c.serverVersion = string(version)
48+
pos := 1 + len(version)
4749

4850
// connection id length is 4
4951
c.connectionID = binary.LittleEndian.Uint32(data[pos : pos+4])
@@ -68,7 +70,7 @@ func (c *Conn) readInitialHandshake() error {
6870

6971
if len(data) > pos {
7072
// skip server charset
71-
//c.charset = data[pos]
73+
// c.charset = data[pos]
7274
pos += 1
7375

7476
c.status = binary.LittleEndian.Uint16(data[pos : pos+2])
@@ -194,14 +196,14 @@ func (c *Conn) writeAuthHandshake() error {
194196
capability |= CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA
195197
}
196198

197-
//packet length
198-
//capability 4
199-
//max-packet size 4
200-
//charset 1
201-
//reserved all[0] 23
202-
//username
203-
//auth
204-
//mysql_native_password + null-terminated
199+
// packet length
200+
// capability 4
201+
// max-packet size 4
202+
// charset 1
203+
// reserved all[0] 23
204+
// username
205+
// auth
206+
// mysql_native_password + null-terminated
205207
length := 4 + 4 + 1 + 23 + len(c.user) + 1 + len(authRespLEI) + len(auth) + 21 + 1
206208
if addNull {
207209
length++

client/conn.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Conn struct {
2424
tlsConfig *tls.Config
2525
proto string
2626

27+
serverVersion string
2728
// server capabilities
2829
capability uint32
2930
// client-set capabilities only
@@ -193,6 +194,10 @@ func (c *Conn) GetDB() string {
193194
return c.db
194195
}
195196

197+
func (c *Conn) GetServerVersion() string {
198+
return c.serverVersion
199+
}
200+
196201
func (c *Conn) Execute(command string, args ...interface{}) (*Result, error) {
197202
if len(args) == 0 {
198203
return c.exec(command)

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ require (
1515
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
1616
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07
1717
github.com/stretchr/testify v1.8.0
18+
golang.org/x/mod v0.3.0
1819
golang.org/x/tools v0.0.0-20201125231158-b5590deeca9b // indirect
1920
)

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
7373
golang.org/x/exp v0.0.0-20181106170214-d68db9428509/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
7474
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
7575
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
76+
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
7677
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
7778
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
7879
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

replication/replication_test.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/google/uuid"
1414
. "github.com/pingcap/check"
15+
"golang.org/x/mod/semver"
1516

1617
"github.com/go-mysql-org/go-mysql/client"
1718
"github.com/go-mysql-org/go-mysql/mysql"
@@ -88,7 +89,7 @@ func (t *testSyncerSuite) testSync(c *C, s *BinlogStreamer) {
8889
}
8990
}()
9091

91-
//use mixed format
92+
// use mixed format
9293
t.testExecute(c, "SET SESSION binlog_format = 'MIXED'")
9394

9495
str := `DROP TABLE IF EXISTS test_replication`
@@ -117,7 +118,7 @@ func (t *testSyncerSuite) testSync(c *C, s *BinlogStreamer) {
117118

118119
t.testExecute(c, str)
119120

120-
//use row format
121+
// use row format
121122
t.testExecute(c, "SET SESSION binlog_format = 'ROW'")
122123

123124
t.testExecute(c, `INSERT INTO test_replication (str, f, i, e, b, y, da, ts, dt, tm, de, t, bb, se)
@@ -294,7 +295,7 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
294295
}
295296

296297
func (t *testSyncerSuite) testPositionSync(c *C) {
297-
//get current master binlog file and position
298+
// get current master binlog file and position
298299
r, err := t.c.Execute("SHOW MASTER STATUS")
299300
c.Assert(err, IsNil)
300301
binFile, _ := r.GetString(0, 0)
@@ -303,11 +304,18 @@ func (t *testSyncerSuite) testPositionSync(c *C) {
303304
s, err := t.b.StartSync(mysql.Position{Name: binFile, Pos: uint32(binPos)})
304305
c.Assert(err, IsNil)
305306

306-
// check we have set Slave_UUID
307307
r, err = t.c.Execute("SHOW SLAVE HOSTS")
308308
c.Assert(err, IsNil)
309-
slaveUUID, _ := r.GetString(0, 4)
310-
c.Assert(slaveUUID, HasLen, 36)
309+
310+
// List of replicas must not be empty
311+
c.Assert(r.Values, Not(HasLen), 0)
312+
313+
// Slave_UUID is empty for mysql 8.0.28+ (8.0.32 still broken)
314+
if semver.Compare(t.c.GetServerVersion(), "8.0.28") < 0 {
315+
// check we have set Slave_UUID
316+
slaveUUID, _ := r.GetString(0, 4)
317+
c.Assert(slaveUUID, HasLen, 36)
318+
}
311319

312320
// Test re-sync.
313321
time.Sleep(100 * time.Millisecond)

0 commit comments

Comments
 (0)