Signed-off-by: Arindam Nayak <arindam.nayak@outlook.com>

fix the test error
This commit is contained in:
Arindam Nayak 2019-11-06 22:39:04 +05:30
Родитель 316dabfd8c
Коммит 976242f80c
12 изменённых файлов: 51 добавлений и 35 удалений

22
dev.env
Просмотреть файл

@ -73,17 +73,6 @@ PATH=$(prepend_path "$PATH" "$VTROOT/dist/chromedriver")
PATH=$(prepend_path "$PATH" "$VTROOT/dist/node/bin")
export PATH
# Etcd path.
case $(uname) in
Linux) etcd_platform=linux;;
Darwin) etcd_platform=darwin;;
esac
ETCD_VERSION=$(cat "${VTROOT}/dist/etcd/.installed_version")
ETCD_BINDIR="${VTROOT}/dist/etcd/etcd-${ETCD_VERSION}-${etcd_platform}-amd64/"
PATH=$(prepend_path "$PATH" "$ETCD_BINDIR")
export PATH
# GOROOT sanity
go_bin=$(which go)
go_env=$(go env | grep GOROOT | cut -f 2 -d\")
@ -113,3 +102,14 @@ export PKG_CONFIG_PATH
alias gt='cd $GOTOP'
alias pt='cd $PYTOP'
alias vt='cd $VTTOP'
# Etcd path.
case $(uname) in
Linux) etcd_platform=linux;;
Darwin) etcd_platform=darwin;;
esac
ETCD_VERSION=$(cat "${VTROOT}/dist/etcd/.installed_version")
ETCD_BINDIR="${VTROOT}/dist/etcd/etcd-${ETCD_VERSION}-${etcd_platform}-amd64/"
PATH=$(prepend_path "$PATH" "$ETCD_BINDIR")
export PATH

Просмотреть файл

@ -17,6 +17,7 @@ limitations under the License.
package cluster
import (
"flag"
"fmt"
"math/rand"
"os"
@ -28,14 +29,20 @@ import (
// DefaultCell : If no cell name is passed, then use following
const DefaultCell = "zone1"
var (
keepData = flag.Bool("keep-data", false, "don't delete the per-test VTDATAROOT subfolders")
)
// LocalProcessCluster Testcases need to use this to iniate a cluster
type LocalProcessCluster struct {
Keyspaces []Keyspace
Cell string
BaseTabletUID int
Hostname string
TopoPort int
TmpDirectory string
Keyspaces []Keyspace
Cell string
BaseTabletUID int
Hostname string
TopoPort int
TmpDirectory string
OriginalVTDATAROOT string
CurrentVTDATAROOT string
VtgateMySQLPort int
VtgateGrpcPort int
@ -238,7 +245,7 @@ func (cluster *LocalProcessCluster) StartVtgate() (err error) {
cluster.VtgateMySQLPort,
cluster.Cell,
cluster.Cell,
cluster.Hostname,
cluster.Hostname,
"MASTER,REPLICA",
cluster.topoProcess.Port,
cluster.TmpDirectory,
@ -248,6 +255,16 @@ func (cluster *LocalProcessCluster) StartVtgate() (err error) {
return cluster.VtgateProcess.Setup()
}
// NewCluster instantiates a new cluster
func NewCluster(cell string, hostname string) *LocalProcessCluster {
cluster := &LocalProcessCluster{Cell: cell, Hostname: hostname}
cluster.OriginalVTDATAROOT = os.Getenv("VTDATAROOT")
cluster.CurrentVTDATAROOT = path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("vtroot_%d", cluster.GetAndReservePort()))
_ = createDirectory(cluster.CurrentVTDATAROOT, 0700)
_ = os.Setenv("VTDATAROOT", cluster.CurrentVTDATAROOT)
return cluster
}
// ReStartVtgate starts vtgate with updated configs
func (cluster *LocalProcessCluster) ReStartVtgate() (err error) {
err = cluster.VtgateProcess.TearDown()
@ -291,7 +308,7 @@ func (cluster *LocalProcessCluster) Teardown() (err error) {
return
}
if err = cluster.topoProcess.TearDown(cluster.Cell); err != nil {
if err = cluster.topoProcess.TearDown(cluster.Cell, cluster.OriginalVTDATAROOT, cluster.CurrentVTDATAROOT, *keepData); err != nil {
log.Error(err.Error())
return
}

Просмотреть файл

@ -95,7 +95,7 @@ func (etcd *EtcdProcess) Setup() (err error) {
}
// TearDown shutdowns the running mysqld service
func (etcd *EtcdProcess) TearDown(Cell string) error {
func (etcd *EtcdProcess) TearDown(Cell string, originalVtRoot string, currentRoot string, keepdata bool) error {
if etcd.proc == nil || etcd.exit == nil {
return nil
}
@ -104,7 +104,11 @@ func (etcd *EtcdProcess) TearDown(Cell string) error {
// Attempt graceful shutdown with SIGTERM first
_ = etcd.proc.Process.Signal(syscall.SIGTERM)
_ = os.RemoveAll(etcd.DataDirectory)
if !*keepData {
_ = os.RemoveAll(etcd.DataDirectory)
_ = os.RemoveAll(currentRoot)
}
_ = os.Setenv("VTDATAROOT", originalVtRoot)
select {
case err := <-etcd.exit:
etcd.proc = nil

Просмотреть файл

@ -67,7 +67,7 @@ func (mysqlctl *MysqlctlProcess) Stop() (err error) {
"-tablet_uid", fmt.Sprintf("%d", mysqlctl.TabletUID),
"shutdown",
)
return tmpProcess.Run()
return tmpProcess.Start()
}
// MysqlCtlProcessInstance returns a Mysqlctl handle for mysqlctl process

Просмотреть файл

@ -133,9 +133,6 @@ func (vtctld *VtctldProcess) TearDown() error {
return nil
}
os.RemoveAll(vtctld.LogDir)
//os.RemoveAll(path.Join(vtctld.Directory, "backups"))
// Attempt graceful shutdown with SIGTERM first
vtctld.proc.Process.Signal(syscall.SIGTERM)

Просмотреть файл

@ -180,7 +180,7 @@ func VtgateProcessInstance(port int, grpcPort int, mySQLServerPort int, cell str
Port: port,
GrpcPort: grpcPort,
MySQLServerPort: mySQLServerPort,
MySQLServerSocketPath: "/tmp/mysql.sock",
MySQLServerSocketPath: path.Join(tmpDirectory, "mysql.sock"),
Cell: cell,
CellsToWatch: cellsToWatch,
TabletTypesToWait: tabletTypesToWait,

Просмотреть файл

@ -154,8 +154,6 @@ func (vttablet *VttabletProcess) TearDown() error {
// Attempt graceful shutdown with SIGTERM first
vttablet.proc.Process.Signal(syscall.SIGTERM)
os.RemoveAll(vttablet.Directory)
select {
case err := <-vttablet.exit:
vttablet.proc = nil
@ -176,7 +174,7 @@ func VttabletProcessInstance(port int, grpcPort int, tabletUID int, cell string,
vttablet := &VttabletProcess{
Name: "vttablet",
Binary: "vttablet",
FileToLogQueries: path.Join(tmpDirectory, fmt.Sprintf("/vt_%010d/vttable.pid", tabletUID)),
FileToLogQueries: path.Join(tmpDirectory, fmt.Sprintf("/vt_%010d/querylog.txt", tabletUID)),
Directory: path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("/vt_%010d", tabletUID)),
TabletPath: fmt.Sprintf("%s-%010d", cell, tabletUID),
ServiceMap: "grpc-queryservice,grpc-tabletmanager,grpc-updatestream",
@ -191,7 +189,7 @@ func VttabletProcessInstance(port int, grpcPort int, tabletUID int, cell string,
FileBackupStorageRoot: path.Join(os.Getenv("VTDATAROOT"), "/backups"),
Port: port,
GrpcPort: grpcPort,
PidFile: path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("/vt_%010d/vttable.pid", tabletUID)),
PidFile: path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("/vt_%010d/vttablet.pid", tabletUID)),
VtctldAddress: fmt.Sprintf("http://%s:%d", hostname, vtctldPort),
ExtraArgs: extraArgs,
}

Просмотреть файл

@ -63,7 +63,7 @@ func TestMain(m *testing.M) {
flag.Parse()
exitCode := func() int {
clusterInstance = &cluster.LocalProcessCluster{Cell: cell, Hostname: "localhost"}
clusterInstance = cluster.NewCluster(cell, "localhost")
defer clusterInstance.Teardown()
// Start topo server

Просмотреть файл

@ -168,7 +168,7 @@ func TestMain(m *testing.M) {
flag.Parse()
exitCode := func() int {
clusterInstance = &cluster.LocalProcessCluster{Cell: Cell, Hostname: "localhost"}
clusterInstance = cluster.NewCluster(Cell, "localhost")
defer clusterInstance.Teardown()
// Start topo server

Просмотреть файл

@ -82,7 +82,7 @@ func TestMain(m *testing.M) {
flag.Parse()
exitCode := func() int {
clusterInstance = &cluster.LocalProcessCluster{Cell: cell, Hostname: hostname}
clusterInstance = cluster.NewCluster(cell, hostname)
defer clusterInstance.Teardown()
// Start topo server

Просмотреть файл

@ -98,7 +98,7 @@ func TestMain(m *testing.M) {
flag.Parse()
exitcode, err := func() (int, error) {
clusterInstance = &cluster.LocalProcessCluster{Cell: cell, Hostname: hostname}
clusterInstance = cluster.NewCluster(cell, hostname)
defer clusterInstance.Teardown()
// Reserve vtGate port in order to pass it to vtTablet

Просмотреть файл

@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
flag.Parse()
exitcode, err := func() (int, error) {
clusterInstance = &cluster.LocalProcessCluster{Cell: cell, Hostname: hostname}
clusterInstance = cluster.NewCluster(cell, hostname)
defer clusterInstance.Teardown()
// Start topo server