vitess.io/vitess@v0.16.2/go/test/endtoend/vtorc/primaryfailure/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 primaryfailure 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: 12, 36 NumRdonly: 3, 37 UIDBase: 100, 38 }) 39 cellInfos = append(cellInfos, &utils.CellInfo{ 40 CellName: utils.Cell2, 41 NumReplicas: 2, 42 NumRdonly: 0, 43 UIDBase: 200, 44 }) 45 46 exitcode, err := func() (int, error) { 47 var err error 48 clusterInfo, err = utils.CreateClusterAndStartTopo(cellInfos) 49 if err != nil { 50 return 1, err 51 } 52 53 return m.Run(), nil 54 }() 55 56 cluster.PanicHandler(nil) 57 58 if clusterInfo != nil { 59 // stop vtorc first otherwise its logs get polluted 60 // with instances being unreachable triggering unnecessary operations 61 for _, vtorcProcess := range clusterInfo.ClusterInstance.VTOrcProcesses { 62 _ = vtorcProcess.TearDown() 63 } 64 65 for _, cellInfo := range clusterInfo.CellInfos { 66 utils.KillTablets(cellInfo.ReplicaTablets) 67 utils.KillTablets(cellInfo.RdonlyTablets) 68 } 69 clusterInfo.ClusterInstance.Keyspaces[0].Shards[0].Vttablets = nil 70 clusterInfo.ClusterInstance.Teardown() 71 } 72 73 if err != nil { 74 fmt.Printf("%v\n", err) 75 os.Exit(1) 76 } else { 77 os.Exit(exitcode) 78 } 79 }