Skip to content

Commit

Permalink
test: add end to end test for UNION collation handling
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Feb 6, 2024
1 parent 7fb0f26 commit dfe8e6e
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 0 deletions.
66 changes: 66 additions & 0 deletions go/test/endtoend/vtgate/queries/collations/collations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package collations

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/utils"
)

func start(t *testing.T) (utils.MySQLCompare, func()) {
// ensure that the vschema and the tables have been created before running any tests
_ = utils.WaitForAuthoritative(t, keyspaceName, "t1", clusterInstance.VtgateProcess.ReadVSchema)
_ = utils.WaitForAuthoritative(t, keyspaceName, "t2", clusterInstance.VtgateProcess.ReadVSchema)

mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams)
require.NoError(t, err)

deleteAll := func() {
_, _ = utils.ExecAllowError(t, mcmp.VtConn, "set workload = oltp")

tables := []string{"t1", "t2"}
for _, table := range tables {
_, _ = mcmp.ExecAndIgnore("delete from " + table)
}
}

deleteAll()

return mcmp, func() {
deleteAll()
mcmp.Close()
cluster.PanicHandler(t)
}
}

func TestCollationTyping(t *testing.T) {
utils.SkipIfBinaryIsBelowVersion(t, 19, "vtgate")

mcmp, closer := start(t)
defer closer()
mcmp.Exec("insert into t1(id, name) values(1,'ß'), (2,'s'), (3,'ss')")
mcmp.Exec("insert into t2(id, name) values(1,'ß'), (2,'s'), (3,'ss')")

res := utils.Exec(t, mcmp.VtConn, `vexplain plan SELECT name from t1 union select name from t2`)
fmt.Printf("%v", res.Rows)
mcmp.Exec(`SELECT name from t1 union select name from t2`)
}
94 changes: 94 additions & 0 deletions go/test/endtoend/vtgate/queries/collations/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package collations

import (
_ "embed"
"flag"
"fmt"
"os"
"testing"

"vitess.io/vitess/go/test/endtoend/utils"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
mysqlParams mysql.ConnParams
keyspaceName = "ks_aggr"
cell = "test_aggr"

//go:embed schema.sql
schemaSQL string

//go:embed vschema.json
vschema string
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode := func() int {
clusterInstance = cluster.NewCluster(cell, "localhost")
defer clusterInstance.Teardown()

// Start topo server
err := clusterInstance.StartTopo()
if err != nil {
return 1
}

// Start keyspace
keyspace := &cluster.Keyspace{
Name: keyspaceName,
SchemaSQL: schemaSQL,
VSchema: vschema,
}
clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal"}
err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false)
if err != nil {
return 1
}

clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true")
// Start vtgate
err = clusterInstance.StartVtgate()
if err != nil {
return 1
}

vtParams = clusterInstance.GetVTParams(keyspaceName)

// create mysql instance and connection parameters
conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL)
if err != nil {
fmt.Println(err)
return 1
}
defer closer()
mysqlParams = conn

return m.Run()
}()
os.Exit(exitCode)
}
13 changes: 13 additions & 0 deletions go/test/endtoend/vtgate/queries/collations/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table t1
(
id bigint,
name varchar(255) collate utf8_general_mysql500_ci,
primary key (id)
) Engine = InnoDB;

create table t2
(
id bigint,
name varchar(255) collate utf8_general_mysql500_ci,
primary key (id)
) ENGINE = InnoDB;
29 changes: 29 additions & 0 deletions go/test/endtoend/vtgate/queries/collations/vschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
},
"unicode_loose_xxhash": {
"type": "unicode_loose_xxhash"
}
},
"tables": {
"t1": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
},
"t2": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
}
}
}
9 changes: 9 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,15 @@
"RetryMax": 2,
"Tags": ["upgrade_downgrade_query_serving_queries"]
},
"vtgate_queries_collations": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/vtgate/queries/collations"],
"Command": [],
"Manual": false,
"Shard": "vtgate_queries",
"RetryMax": 2,
"Tags": ["upgrade_downgrade_query_serving_queries"]
},
"vtgate_queries_foundrows": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/vtgate/queries/foundrows"],
Expand Down

0 comments on commit dfe8e6e

Please sign in to comment.