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

Reparenting endtoend testcases in Go migrated from Python [+ github actions] #5604

Merged
merged 13 commits into from
Dec 31, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
jobs:

build:
name: Cluster End-to-End Test
name: Cluster End-to-End Test for Shard 11
runs-on: ubuntu-latest
steps:

Expand All @@ -25,10 +25,7 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
go mod download

- name: Run make minimaltools
- name: cluster_endtoend_shard_11
run: |
make minimaltools

- name: cluster_endtoend
run: |
make e2e_test_cluster
source build.env
go run test.go -docker=false -print-log -shard 11
31 changes: 31 additions & 0 deletions .github/workflows/cluster_endtoend_shard12.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: cluster_endtoend
on: [push, pull_request]
jobs:

build:
name: Cluster End-to-End Test for Shard 12
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13

- name: Check out code
uses: actions/checkout@v2

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y mysql-server mysql-client make unzip g++ etcd curl git wget
sudo service mysql stop
sudo service etcd stop
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
go mod download

- name: cluster_endtoend_shard_12
run: |
source build.env
go run test.go -docker=false -print-log -shard 12
31 changes: 31 additions & 0 deletions .github/workflows/cluster_endtoend_shard13.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: cluster_endtoend
on: [push, pull_request]
jobs:

build:
name: Cluster End-to-End Test for Shard 13
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13

- name: Check out code
uses: actions/checkout@v2

- name: Get dependencies
run: |
sudo apt-get update
sudo apt-get install -y mysql-server mysql-client make unzip g++ etcd curl git wget
sudo service mysql stop
sudo service etcd stop
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
go mod download

- name: cluster_endtoend_shard_13
run: |
source build.env
go run test.go -docker=false -print-log -shard 13
10 changes: 6 additions & 4 deletions go/test/endtoend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ So far we have converted the following Python end to end test cases
- sharded tests
- tabletmanager tests
- vtgate v3 tests

### In-progress
- Inital sharding
- resharding
- vsplit

- vsplit
- reparent

### In-progress
- Backup
- Encryption

After a Python test is migrated in Go it will be removed from end to end ci test run by updating the shard value to 5 in `test/config.json`

Expand Down
5 changes: 0 additions & 5 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ func (cluster *LocalProcessCluster) LaunchCluster(keyspace *Keyspace, shards []S
// Create shard
for _, shard := range shards {
for _, tablet := range shard.Vttablets {
err = cluster.VtctlclientProcess.InitTablet(tablet, tablet.Cell, keyspace.Name, cluster.Hostname, shard.Name)
if err != nil {
log.Error(err)
return
}

// Setup MysqlctlProcess
tablet.MysqlctlProcess = *MysqlCtlProcessInstance(tablet.TabletUID, tablet.MySQLPort, cluster.TmpDirectory)
Expand Down
10 changes: 8 additions & 2 deletions go/test/endtoend/cluster/mysqlctl_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type MysqlctlProcess struct {
MySQLPort int
InitDBFile string
ExtraArgs []string
InitMysql bool
}

// InitDb executes mysqlctl command to add cell info
Expand Down Expand Up @@ -74,8 +75,12 @@ func (mysqlctl *MysqlctlProcess) StartProcess() (*exec.Cmd, error) {
if len(mysqlctl.ExtraArgs) > 0 {
tmpProcess.Args = append(tmpProcess.Args, mysqlctl.ExtraArgs...)
}
tmpProcess.Args = append(tmpProcess.Args, "init",
"-init_db_sql_file", mysqlctl.InitDBFile)
if mysqlctl.InitMysql {
tmpProcess.Args = append(tmpProcess.Args, "init",
"-init_db_sql_file", mysqlctl.InitDBFile)
} else {
tmpProcess.Args = append(tmpProcess.Args, "start")
}
return tmpProcess, tmpProcess.Start()
}

Expand Down Expand Up @@ -121,6 +126,7 @@ func MysqlCtlProcessInstance(tabletUID int, mySQLPort int, tmpDirectory string)
}
mysqlctl.MySQLPort = mySQLPort
mysqlctl.TabletUID = tabletUID
mysqlctl.InitMysql = true
return mysqlctl
}

Expand Down
3 changes: 3 additions & 0 deletions go/test/endtoend/cluster/vtctlclient_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func (vtctlclient *VtctlClientProcess) InitTablet(tablet *Vttablet, cell string,
if tablet.MySQLPort > 0 {
args = append(args, "-mysql_port", fmt.Sprintf("%d", tablet.MySQLPort))
}
if tablet.GrpcPort > 0 {
args = append(args, "-grpc_port", fmt.Sprintf("%d", tablet.GrpcPort))
}
args = append(args, fmt.Sprintf("%s-%010d", cell, tablet.TabletUID), tabletType)
return vtctlclient.ExecuteCommand(args...)
}
26 changes: 22 additions & 4 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (vttablet *VttabletProcess) Setup() (err error) {

if vttablet.ServingStatus != "" {
if err = vttablet.WaitForTabletType(vttablet.ServingStatus); err != nil {
return fmt.Errorf("process '%s' timed out after 60s (err: %s)", vttablet.Name, <-vttablet.exit)
return fmt.Errorf("process '%s' timed out after 10s (err: %s)", vttablet.Name, err)
}
}
return nil
Expand Down Expand Up @@ -185,9 +185,16 @@ func (vttablet *VttabletProcess) GetTabletStatus() string {

// WaitForTabletType waits till the tablet status reaches desired type
func (vttablet *VttabletProcess) WaitForTabletType(expectedType string) error {
return vttablet.WaitForTabletTypes([]string{expectedType})
}

// WaitForTabletTypes waits till the tablet reaches to any of the provided status
func (vttablet *VttabletProcess) WaitForTabletTypes(expectedTypes []string) error {
timeout := time.Now().Add(10 * time.Second)
var status string
for time.Now().Before(timeout) {
if vttablet.GetTabletStatus() == expectedType {
status = vttablet.GetTabletStatus()
if contains(expectedTypes, status) {
return nil
}
select {
Expand All @@ -197,7 +204,17 @@ func (vttablet *VttabletProcess) WaitForTabletType(expectedType string) error {
time.Sleep(300 * time.Millisecond)
}
}
return fmt.Errorf("Vttablet %s, expected status not reached", vttablet.TabletPath)
return fmt.Errorf("Vttablet %s, current status = %s, expected status [%s] not reached ",
vttablet.TabletPath, status, strings.Join(expectedTypes, ","))
}

func contains(arr []string, str string) bool {
for _, a := range arr {
if a == str {
return true
}
}
return false
}

// WaitForBinLogPlayerCount waits till binlog player count var matches
Expand Down Expand Up @@ -266,7 +283,8 @@ func (vttablet *VttabletProcess) TearDown() error {

// CreateDB creates the database for keyspace
func (vttablet *VttabletProcess) CreateDB(keyspace string) error {
_, err := vttablet.QueryTablet(fmt.Sprintf("create database vt_%s", keyspace), keyspace, false)
_, _ = vttablet.QueryTablet(fmt.Sprintf("drop database IF EXISTS vt_%s", keyspace), keyspace, false)
_, err := vttablet.QueryTablet(fmt.Sprintf("create database IF NOT EXISTS vt_%s", keyspace), keyspace, false)
return err
}

Expand Down
175 changes: 175 additions & 0 deletions go/test/endtoend/reparent/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
Copyright 2019 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 reparent

import (
"context"
"flag"
"fmt"
"os"
"os/exec"
"path"
"testing"

"github.com/stretchr/testify/assert"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
tmc "vitess.io/vitess/go/vt/vttablet/grpctmclient"
)

var (
// ClusterInstance instance to be used for test with different params
clusterInstance *cluster.LocalProcessCluster
tmClient *tmc.Client
keyspaceName = "ks"
shardName = "0"
shard1Name = "0000000000000000-ffffffffffffffff"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to use this instead of just 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, copied from Python ones. Will test with 0-f

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it to -80. Let me know if that works for the test

Copy link
Member

Choose a reason for hiding this comment

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

I looked at the original python test case. I think this does need to be the same as it was in python.
Also, in the python test, we basically run the same scenario for shard0 and shard1, the only difference is how the shard is represented: 0 vs 0000...-ffff.... We should preserve that while porting rather than changing the test to only have 1 master + 1 replica when the shard is represented as 0000...-ffff...

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 have reverted the range to 000...-ffff....
As wrt to replica counts I have only used master-replica as we just need to verify replication in a replica in range-based test.
As opposed to other Tests like TestChangeTypeSemiSync and TestReparentFromOutside need 4 replicas setup which is already present in Shard0.

keyspaceShard = keyspaceName + "/" + shardName
dbName = "vt_" + keyspaceName
username = "vt_dba"
hostname = "localhost"
cell1 = "zone1"
cell2 = "zone2"
insertSQL = "insert into vt_insert_test(id, msg) values (%d, 'test %d')"
sqlSchema = `
create table vt_insert_test (
id bigint,
msg varchar(64),
primary key (id)
) Engine=InnoDB
`
// Tablets for for shard0
tablet62344 *cluster.Vttablet
tablet62044 *cluster.Vttablet
tablet41983 *cluster.Vttablet
tablet31981 *cluster.Vttablet

// Tablets for for shard1
masterTablet *cluster.Vttablet
replicaTablet *cluster.Vttablet
)

func TestMain(m *testing.M) {
flag.Parse()

exitCode := func() int {
clusterInstance = cluster.NewCluster(cell1, hostname)
defer clusterInstance.Teardown()

// Launch keyspace
keyspace := &cluster.Keyspace{Name: keyspaceName}

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

// Adding another cell in the same cluster
err = clusterInstance.TopoProcess.ManageTopoDir("mkdir", "/vitess/"+cell2)
if err != nil {
return 1
}
err = clusterInstance.VtctlProcess.AddCellInfo(cell2)
if err != nil {
return 1
}

tablet62344 = clusterInstance.GetVttabletInstance("replica", 62344, "")
tablet62044 = clusterInstance.GetVttabletInstance("replica", 62044, "")
tablet41983 = clusterInstance.GetVttabletInstance("replica", 41983, "")
tablet31981 = clusterInstance.GetVttabletInstance("replica", 31981, cell2)

shard0 := &cluster.Shard{Name: shardName}
shard0.Vttablets = []*cluster.Vttablet{tablet62344, tablet62044, tablet41983, tablet31981}

// Initiate shard1 - required for ranged based reparenting
masterTablet = clusterInstance.GetVttabletInstance("replica", 0, "")
replicaTablet = clusterInstance.GetVttabletInstance("replica", 0, "")

shard1 := &cluster.Shard{Name: shard1Name}
shard1.Vttablets = []*cluster.Vttablet{masterTablet, replicaTablet}

clusterInstance.VtTabletExtraArgs = []string{
"-lock_tables_timeout", "5s",
"-enable_semi_sync",
}

// Initialize Cluster
err = clusterInstance.LaunchCluster(keyspace, []cluster.Shard{*shard0, *shard1})
if err != nil {
return 1
}

//Start MySql
var mysqlCtlProcessList []*exec.Cmd
for _, shard := range clusterInstance.Keyspaces[0].Shards {
for _, tablet := range shard.Vttablets {
fmt.Println("Starting MySql for tablet ", tablet.Alias)
if proc, err := tablet.MysqlctlProcess.StartProcess(); err != nil {
return 1
} else {
mysqlCtlProcessList = append(mysqlCtlProcessList, proc)
}
}
}

// Wait for mysql processes to start
for _, proc := range mysqlCtlProcessList {
if err := proc.Wait(); err != nil {
return 1
}
}

// We do not need semiSync for this test case.
clusterInstance.EnableSemiSync = false

// create tablet manager client
tmClient = tmc.NewClient()

return m.Run()
}()
os.Exit(exitCode)
}

func getMysqlConnParam(tablet *cluster.Vttablet) mysql.ConnParams {
connParams := mysql.ConnParams{
Uname: username,
DbName: dbName,
UnixSocket: path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("/vt_%010d/mysql.sock", tablet.TabletUID)),
}
return connParams
}

func runSQL(ctx context.Context, t *testing.T, sql string, tablet *cluster.Vttablet) *sqltypes.Result {
// Get Connection
tabletParams := getMysqlConnParam(tablet)
conn, err := mysql.Connect(ctx, &tabletParams)
assert.Nil(t, err)
defer conn.Close()

// runSQL
return execute(t, conn, sql)
}

func execute(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
t.Helper()
qr, err := conn.ExecuteFetch(query, 1000, true)
assert.Nil(t, err)
return qr
}
Loading