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

decider: endtoend test infrastructure + tests #6770

Merged
merged 6 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ endif
# Safe, since this code isn't performance critical.
export CGO_CFLAGS := -O1

# regenerate rice-box.go when any of the .cnf files change
embed_config:
cd go/vt/mysqlctl
go run github.com/GeertJohan/go.rice/rice embed-go
Expand Down
3 changes: 3 additions & 0 deletions config/mycnf/default-fast.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ innodb_doublewrite=0
# https://github.com/vitessio/vitess/issues/5396

sql_mode = STRICT_TRANS_TABLES

# set a short heartbeat interval in order to detect failures quickly
slave_net_timeout = 4
26 changes: 24 additions & 2 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type LocalProcessCluster struct {
VtgateProcess VtgateProcess
VtworkerProcess VtworkerProcess
VtbackupProcess VtbackupProcess
OrcProcess *OrchestratorProcess

nextPortForProcess int

Expand Down Expand Up @@ -349,11 +350,11 @@ func (cluster *LocalProcessCluster) StartKeyspace(keyspace Keyspace, shardNames
return
}

// LaunchCluster creates the skeleton for a cluster by creating keyspace
// SetupCluster creates the skeleton for a cluster by creating keyspace
// shards and initializing tablets and mysqlctl processes.
// This does not start any process and user have to explicitly start all
// the required services (ex topo, vtgate, mysql and vttablet)
func (cluster *LocalProcessCluster) LaunchCluster(keyspace *Keyspace, shards []Shard) (err error) {
func (cluster *LocalProcessCluster) SetupCluster(keyspace *Keyspace, shards []Shard) (err error) {

log.Infof("Starting keyspace: %v", keyspace.Name)

Expand Down Expand Up @@ -504,6 +505,12 @@ func (cluster *LocalProcessCluster) Teardown() {
log.Errorf("Error in vtgate teardown: %v", err)
}

if cluster.OrcProcess != nil {
if err := cluster.OrcProcess.TearDown(); err != nil {
log.Errorf("Error in orchestrator teardown: %v", err)
}
}

var mysqlctlProcessList []*exec.Cmd
for _, keyspace := range cluster.Keyspaces {
for _, shard := range keyspace.Shards {
Expand Down Expand Up @@ -667,6 +674,17 @@ func (cluster *LocalProcessCluster) NewVttabletInstance(tabletType string, UID i
}
}

// NewOrcProcess creates a new OrchestratorProcess object
func (cluster *LocalProcessCluster) NewOrcProcess(configFile string) *OrchestratorProcess {
base := VtctlProcessInstance(cluster.TopoProcess.Port, cluster.Hostname)
base.Binary = "orchestrator"
return &OrchestratorProcess{
VtctlProcess: *base,
LogDir: cluster.TmpDirectory,
Config: configFile,
}
}

// VtprocessInstanceFromVttablet creates a new vttablet object
func (cluster *LocalProcessCluster) VtprocessInstanceFromVttablet(tablet *Vttablet, shardName string, ksName string) *VttabletProcess {
return VttabletProcessInstance(tablet.HTTPPort,
Expand Down Expand Up @@ -707,6 +725,10 @@ func (cluster *LocalProcessCluster) StartVttablet(tablet *Vttablet, servingStatu
return tablet.VttabletProcess.Setup()
}

//func (cluster *LocalProcessCluster) NewOrcInstance() OrchestratorProcess {
//
//}

func getCoveragePath(fileName string) string {
covDir := os.Getenv("COV_DIR")
if covDir == "" {
Expand Down
103 changes: 103 additions & 0 deletions go/test/endtoend/cluster/orchestrator_process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2020 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 cluster

import (
"os"
"os/exec"
"path"
"strings"
"syscall"
"time"

"vitess.io/vitess/go/vt/log"
)

// OrchestratorProcess is a test struct for running
// orchestrator as a separate process for testing
type OrchestratorProcess struct {
VtctlProcess
LogDir string
ExtraArgs []string
Config string
proc *exec.Cmd
exit chan error
}

// Setup starts orc process with required arguements
func (orc *OrchestratorProcess) Setup() (err error) {

/* minimal command line arguments:
$ orchestrator -topo_implementation etcd2 -topo_global_server_address localhost:2379 -topo_global_root /vitess/global
-config config/orchestrator/default.json -alsologtostderr http
*/
orc.proc = exec.Command(
orc.Binary,
"-topo_implementation", orc.TopoImplementation,
"-topo_global_server_address", orc.TopoGlobalAddress,
"-topo_global_root", orc.TopoGlobalRoot,
"-config", orc.Config,
)
if *isCoverage {
orc.proc.Args = append(orc.proc.Args, "-test.coverprofile="+getCoveragePath("orc.out"))
}

orc.proc.Args = append(orc.proc.Args, orc.ExtraArgs...)
orc.proc.Args = append(orc.proc.Args, "-alsologtostderr", "http")

errFile, _ := os.Create(path.Join(orc.LogDir, "orc-stderr.txt"))
orc.proc.Stderr = errFile

orc.proc.Env = append(orc.proc.Env, os.Environ()...)

log.Infof("Running orc with command: %v", strings.Join(orc.proc.Args, " "))

err = orc.proc.Start()
if err != nil {
return
}

orc.exit = make(chan error)
go func() {
if orc.proc != nil {
orc.exit <- orc.proc.Wait()
}
}()

return nil
}
deepthi marked this conversation as resolved.
Show resolved Hide resolved

// TearDown shuts down the running orchestrator service
func (orc *OrchestratorProcess) TearDown() error {
if orc.proc == nil || orc.exit == nil {
return nil
}
// Attempt graceful shutdown with SIGTERM first
_ = orc.proc.Process.Signal(syscall.SIGTERM)

select {
case <-orc.exit:
orc.proc = nil
return nil

case <-time.After(10 * time.Second):
_ = orc.proc.Process.Kill()
orc.proc = nil
return <-orc.exit
}
}
Loading