vitess.io/vitess@v0.16.2/go/test/endtoend/vtorc/general/main_test.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package general 18 19 import ( 20 "fmt" 21 "os" 22 "testing" 23 24 "vitess.io/vitess/go/test/endtoend/cluster" 25 "vitess.io/vitess/go/test/endtoend/vtorc/utils" 26 ) 27 28 var clusterInfo *utils.VTOrcClusterInfo 29 30 func TestMain(m *testing.M) { 31 // setup cellInfos before creating the cluster 32 var cellInfos []*utils.CellInfo 33 cellInfos = append(cellInfos, &utils.CellInfo{ 34 CellName: utils.Cell1, 35 NumReplicas: 4, 36 NumRdonly: 1, 37 UIDBase: 100, 38 }) 39 40 exitcode, err := func() (int, error) { 41 var err error 42 clusterInfo, err = utils.CreateClusterAndStartTopo(cellInfos) 43 if err != nil { 44 return 1, err 45 } 46 47 return m.Run(), nil 48 }() 49 50 cluster.PanicHandler(nil) 51 52 if clusterInfo != nil { 53 // stop vtorc first otherwise its logs get polluted 54 // with instances being unreachable triggering unnecessary operations 55 for _, vtorcProcess := range clusterInfo.ClusterInstance.VTOrcProcesses { 56 _ = vtorcProcess.TearDown() 57 } 58 59 for _, cellInfo := range clusterInfo.CellInfos { 60 utils.KillTablets(cellInfo.ReplicaTablets) 61 utils.KillTablets(cellInfo.RdonlyTablets) 62 } 63 clusterInfo.ClusterInstance.Keyspaces[0].Shards[0].Vttablets = nil 64 clusterInfo.ClusterInstance.Teardown() 65 } 66 67 if err != nil { 68 fmt.Printf("%v\n", err) 69 os.Exit(1) 70 } else { 71 os.Exit(exitcode) 72 } 73 }