From bb2bab76384ebdc9843076fc6ef993a77bb8d4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 7 May 2023 09:48:22 +0200 Subject: [PATCH 1/6] tests: select testdb and use MySQL 8.0 by default Without the `USE...` in `TestExecuteMultiple` the test panics as the result in `conn_test.go:108` is nil. ``` $ go test ---------------------------------------------------------------------- PANIC: conn_test.go:92: connTestSuite.TestExecuteMultiple ... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x438592) /usr/lib/golang/src/runtime/panic.go:884 in gopanic /usr/lib/golang/src/runtime/panic.go:260 in panicmem /usr/lib/golang/src/runtime/signal_unix.go:837 in sigpanic conn_test.go:108 in connTestSuite.TestExecuteMultiple.func1 conn.go:273 in Conn.ExecuteMultiple conn_test.go:101 in connTestSuite.TestExecuteMultiple /usr/lib/golang/src/reflect/value.go:370 in Value.Call /home/dvaneeden/go/pkg/mod/github.com/pingcap/check@v0.0.0-20190102082844-67f458068fc8/check.go:836 in suiteRunner.forkTest.func1 /home/dvaneeden/go/pkg/mod/github.com/pingcap/check@v0.0.0-20190102082844-67f458068fc8/check.go:730 in suiteRunner.forkCall.func1 /usr/lib/golang/src/runtime/asm_amd64.s:1598 in goexit ---------------------------------------------------------------------- FAIL: conn_test.go:132: connTestSuite.TestExecuteSelectStreaming conn_test.go:170: c.Assert(err, IsNil) ... value *mysql.MyError = &mysql.MyError{Code:0x416, Message:"No database selected", State:"3D000"} ("ERROR 1046 (3D000): No database selected") ---------------------------------------------------------------------- FAIL: conn_test.go:86: connTestSuite.TestFieldList conn_test.go:88: c.Assert(err, IsNil) ... value *mysql.MyError = &mysql.MyError{Code:0x416, Message:"No database selected", State:"3D000"} ("ERROR 1046 (3D000): No database selected") ---------------------------------------------------------------------- FAIL: conn_test.go:38: connTestSuite.TearDownSuite conn_test.go:43: s.testExecute_DropTable(c) conn_test.go:83: c.Assert(err, IsNil) ... value *mysql.MyError = &mysql.MyError{Code:0x416, Message:"No database selected", State:"3D000"} ("ERROR 1046 (3D000): No database selected") OOPS: 18 passed, 3 FAILED, 1 PANICKED --- FAIL: Test (0.46s) FAIL exit status 1 FAIL github.com/go-mysql-org/go-mysql/client 0.465s ``` --- Makefile | 2 +- client/conn_test.go | 3 +++ docker/resources/waitfor.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bab5efecc..44a0eb2b5 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ build: test: go test --race -timeout 2m ./... -MYSQL_VERSION ?= 5.7 +MYSQL_VERSION ?= 8.0 test-local: docker run --rm -d --network=host --name go-mysql-server \ -e MYSQL_ALLOW_EMPTY_PASSWORD=true \ diff --git a/client/conn_test.go b/client/conn_test.go index a0eca11a2..50ef47eef 100644 --- a/client/conn_test.go +++ b/client/conn_test.go @@ -97,6 +97,9 @@ func (s *connTestSuite) TestExecuteMultiple(c *C) { `THIS IS BOGUS()`, } + _, err := s.c.Execute("USE " + *testDB) + c.Assert(err, IsNil) + count := 0 result, err := s.c.ExecuteMultiple(strings.Join(queries, "; "), func(result *mysql.Result, err error) { switch count { diff --git a/docker/resources/waitfor.sh b/docker/resources/waitfor.sh index 2aab35490..4442f2834 100755 --- a/docker/resources/waitfor.sh +++ b/docker/resources/waitfor.sh @@ -4,7 +4,7 @@ port=$2 echo "Waiting for mysql at $host:$port" while true; do - docker run --rm -it --network=host mysql:5.7 mysql -h$host -P$port -e "SELECT RAND()" >/dev/null + docker run --rm -it --network=host mysql:8.0 mysql -h$host -P$port -e "SELECT RAND()" >/dev/null if [[ $? -eq 0 ]]; then echo 'Connected' break From bb37795b2283366598a8f2d8f4d2cf405887d708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 7 May 2023 09:56:05 +0200 Subject: [PATCH 2/6] Add Go 1.20 to the test matrix and upgrade actions/setup-go --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc83d7590..a6b4dac7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: test: strategy: matrix: - go: [ 1.19, 1.18, 1.17, 1.16 ] + go: [ "1.20", "1.19", "1.18", "1.17", "1.16" ] os: [ ubuntu-22.04, ubuntu-20.04 ] name: Tests Go ${{ matrix.go }} # This name is used in main branch protection rules runs-on: ${{ matrix.os }} @@ -31,7 +31,7 @@ jobs: run: | sudo apt-get install -y make gcc - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - name: Checkout code From 1beae61e0ae4a2ac0e2fe240ea3cdc7d21a75c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 7 May 2023 10:12:23 +0200 Subject: [PATCH 3/6] Update test name to include os --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6b4dac7c..75a3b7ab3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: matrix: go: [ "1.20", "1.19", "1.18", "1.17", "1.16" ] os: [ ubuntu-22.04, ubuntu-20.04 ] - name: Tests Go ${{ matrix.go }} # This name is used in main branch protection rules + name: Tests Go ${{ matrix.go }} on ${{ matrix.os }} # This name is used in main branch protection rules runs-on: ${{ matrix.os }} steps: From c339fdb395a8410b6aa9fba7d986dc2b61faa0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 7 May 2023 10:22:32 +0200 Subject: [PATCH 4/6] TestExecuteMultiple: Assert on nil result --- client/conn_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/conn_test.go b/client/conn_test.go index 50ef47eef..14dee6dc0 100644 --- a/client/conn_test.go +++ b/client/conn_test.go @@ -102,6 +102,8 @@ func (s *connTestSuite) TestExecuteMultiple(c *C) { count := 0 result, err := s.c.ExecuteMultiple(strings.Join(queries, "; "), func(result *mysql.Result, err error) { + c.Assert(result, NotNil) + switch count { // the INSERT/DELETE query have no resultset, but should have set affectedrows // the err should be nil From 6f95e3aea2c978aab086c5562d721b27eb77ce17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 30 Jun 2023 17:32:41 +0200 Subject: [PATCH 5/6] Update test code --- client/conn_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/conn_test.go b/client/conn_test.go index 5ae6f76c4..6dff75085 100644 --- a/client/conn_test.go +++ b/client/conn_test.go @@ -107,11 +107,11 @@ func (s *connTestSuite) TestExecuteMultiple() { } _, err := s.c.Execute("USE " + *testDB) - c.Assert(err, IsNil) + require.Nil(s.T(), err) count := 0 result, err := s.c.ExecuteMultiple(strings.Join(queries, "; "), func(result *mysql.Result, err error) { - c.Assert(result, NotNil) + require.NotNil(s.T(), result) switch count { // the INSERT/DELETE query have no resultset, but should have set affectedrows From bef614aa070de2356b0ac1e4ee79cc121fc93ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 30 Jun 2023 17:37:31 +0200 Subject: [PATCH 6/6] Remove change in conn_test.go --- client/conn_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/conn_test.go b/client/conn_test.go index 6dff75085..e2091d50e 100644 --- a/client/conn_test.go +++ b/client/conn_test.go @@ -111,8 +111,6 @@ func (s *connTestSuite) TestExecuteMultiple() { count := 0 result, err := s.c.ExecuteMultiple(strings.Join(queries, "; "), func(result *mysql.Result, err error) { - require.NotNil(s.T(), result) - switch count { // the INSERT/DELETE query have no resultset, but should have set affectedrows // the err should be nil