vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/schematracker/loadkeyspace/schema_load_keyspace_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 loadkeyspace 18 19 import ( 20 "os" 21 "path" 22 "strings" 23 "testing" 24 "time" 25 26 "github.com/stretchr/testify/require" 27 28 "vitess.io/vitess/go/test/endtoend/utils" 29 30 "vitess.io/vitess/go/test/endtoend/cluster" 31 ) 32 33 var ( 34 clusterInstance *cluster.LocalProcessCluster 35 hostname = "localhost" 36 keyspaceName = "ks" 37 cell = "zone1" 38 sqlSchema = ` 39 create table vt_user ( 40 id bigint, 41 name varchar(64), 42 primary key (id) 43 ) Engine=InnoDB; 44 45 create table main ( 46 id bigint, 47 val varchar(128), 48 primary key(id) 49 ) Engine=InnoDB; 50 51 create table test_table ( 52 id bigint, 53 val varchar(128), 54 primary key(id) 55 ) Engine=InnoDB; 56 ` 57 ) 58 59 func TestLoadKeyspaceWithNoTablet(t *testing.T) { 60 defer cluster.PanicHandler(t) 61 var err error 62 63 clusterInstance = cluster.NewCluster(cell, hostname) 64 defer clusterInstance.Teardown() 65 66 // Start topo server 67 err = clusterInstance.StartTopo() 68 require.NoError(t, err) 69 70 // create keyspace 71 keyspace := &cluster.Keyspace{ 72 Name: keyspaceName, 73 SchemaSQL: sqlSchema, 74 } 75 clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal"} 76 err = clusterInstance.StartUnshardedKeyspace(*keyspace, 0, false) 77 require.NoError(t, err) 78 79 // teardown vttablets 80 for _, vttablet := range clusterInstance.Keyspaces[0].Shards[0].Vttablets { 81 err = vttablet.VttabletProcess.TearDown() 82 require.NoError(t, err) 83 utils.TimeoutAction(t, 1*time.Minute, "timeout - teardown of VTTablet", func() bool { 84 return vttablet.VttabletProcess.GetStatus() == "" 85 }) 86 } 87 88 // Start vtgate with the schema_change_signal flag 89 clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"} 90 err = clusterInstance.StartVtgate() 91 require.NoError(t, err) 92 93 // After starting VTGate we need to leave enough time for resolveAndLoadKeyspace to reach 94 // the schema tracking timeout (5 seconds). 95 utils.TimeoutAction(t, 5*time.Minute, "timeout - could not find 'Unable to get initial schema reload' in 'vtgate-stderr.txt'", func() bool { 96 logDir := clusterInstance.VtgateProcess.LogDir 97 all, _ := os.ReadFile(path.Join(logDir, "vtgate-stderr.txt")) 98 return strings.Contains(string(all), "Unable to get initial schema reload") 99 }) 100 } 101 102 func TestNoInitialKeyspace(t *testing.T) { 103 defer cluster.PanicHandler(t) 104 var err error 105 106 clusterInstance = cluster.NewCluster(cell, hostname) 107 defer clusterInstance.Teardown() 108 109 // Start topo server 110 err = clusterInstance.StartTopo() 111 require.NoError(t, err) 112 113 // Start vtgate with the schema_change_signal flag 114 clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"} 115 err = clusterInstance.StartVtgate() 116 require.NoError(t, err) 117 118 logDir := clusterInstance.VtgateProcess.LogDir 119 120 // teardown vtgate to flush logs 121 err = clusterInstance.VtgateProcess.TearDown() 122 require.NoError(t, err) 123 124 // check info logs 125 all, err := os.ReadFile(path.Join(logDir, "vtgate.INFO")) 126 require.NoError(t, err) 127 require.Contains(t, string(all), "No keyspace to load") 128 }