vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/misc/main_test.go (about) 1 /* 2 Copyright 2022 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 misc 18 19 import ( 20 _ "embed" 21 "flag" 22 "fmt" 23 "os" 24 "testing" 25 26 "vitess.io/vitess/go/test/endtoend/utils" 27 28 "vitess.io/vitess/go/mysql" 29 "vitess.io/vitess/go/test/endtoend/cluster" 30 ) 31 32 var ( 33 clusterInstance *cluster.LocalProcessCluster 34 vtParams mysql.ConnParams 35 mysqlParams mysql.ConnParams 36 keyspaceName = "ks_misc" 37 uks = "uks" 38 cell = "test_misc" 39 40 //go:embed uschema.sql 41 uschemaSQL string 42 43 //go:embed schema.sql 44 schemaSQL string 45 46 //go:embed vschema.json 47 vschema string 48 ) 49 50 func TestMain(m *testing.M) { 51 defer cluster.PanicHandler(nil) 52 flag.Parse() 53 54 exitCode := func() int { 55 clusterInstance = cluster.NewCluster(cell, "localhost") 56 defer clusterInstance.Teardown() 57 58 // Start topo server 59 err := clusterInstance.StartTopo() 60 if err != nil { 61 return 1 62 } 63 64 clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-config-max-result-size", "1000000", 65 "--queryserver-config-query-timeout", "200", 66 "--queryserver-config-query-pool-timeout", "200") 67 // Start Unsharded keyspace 68 ukeyspace := &cluster.Keyspace{ 69 Name: uks, 70 SchemaSQL: uschemaSQL, 71 } 72 err = clusterInstance.StartUnshardedKeyspace(*ukeyspace, 0, false) 73 if err != nil { 74 return 1 75 } 76 77 // Start keyspace 78 keyspace := &cluster.Keyspace{ 79 Name: keyspaceName, 80 SchemaSQL: schemaSQL, 81 VSchema: vschema, 82 } 83 err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false) 84 if err != nil { 85 return 1 86 } 87 88 clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true", "--query-timeout=100") 89 // Start vtgate 90 err = clusterInstance.StartVtgate() 91 if err != nil { 92 return 1 93 } 94 95 vtParams = clusterInstance.GetVTParams(keyspaceName) 96 97 // create mysql instance and connection parameters 98 conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL) 99 if err != nil { 100 fmt.Println(err) 101 return 1 102 } 103 defer closer() 104 mysqlParams = conn 105 return m.Run() 106 }() 107 os.Exit(exitCode) 108 }