-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix + integration test for keyspaces_to_watch routing regression [fixes #7882]
#7873
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
go/test/endtoend/vtgate/keyspace_watches/keyspace_watch_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| Copyright 2021 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. | ||
| */ | ||
|
|
||
| /* | ||
| Test the vtgate's ability to route while watching a subset of keyspaces. | ||
| */ | ||
|
|
||
| package keyspacewatches | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "fmt" | ||
| "math/rand" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| _ "github.com/go-sql-driver/mysql" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "vitess.io/vitess/go/mysql" | ||
| "vitess.io/vitess/go/test/endtoend/cluster" | ||
| ) | ||
|
|
||
| var ( | ||
| vtParams mysql.ConnParams | ||
| keyspaceUnshardedName = "ks1" | ||
| cell = "zone1" | ||
| hostname = "localhost" | ||
| mysqlAuthServerStatic = "mysql_auth_server_static.json" | ||
| sqlSchema = ` | ||
| create table keyspaces_to_watch_test( | ||
| id BIGINT NOT NULL, | ||
| msg VARCHAR(64) NOT NULL, | ||
| PRIMARY KEY (id) | ||
| ) Engine=InnoDB;` | ||
| ) | ||
|
|
||
| // createConfig creates a config file in TmpDir in vtdataroot and writes the given data. | ||
| func createConfig(clusterInstance *cluster.LocalProcessCluster, name, data string) error { | ||
| // creating new file | ||
| f, err := os.Create(clusterInstance.TmpDirectory + "/" + name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if data == "" { | ||
| return nil | ||
| } | ||
|
|
||
| // write the given data | ||
| _, err = fmt.Fprint(f, data) | ||
| return err | ||
| } | ||
|
|
||
| func createCluster() (*cluster.LocalProcessCluster, int) { | ||
| clusterInstance := cluster.NewCluster(cell, hostname) | ||
|
|
||
| // Start topo server | ||
| if err := clusterInstance.StartTopo(); err != nil { | ||
| return nil, 1 | ||
| } | ||
|
|
||
| // create auth server config | ||
| SQLConfig := `{ | ||
| "testuser1": { | ||
| "Password": "testpassword1", | ||
| "UserData": "vtgate client 1" | ||
| } | ||
| }` | ||
| if err := createConfig(clusterInstance, mysqlAuthServerStatic, SQLConfig); err != nil { | ||
| return nil, 1 | ||
| } | ||
|
|
||
| // Start keyspace | ||
| keyspace := &cluster.Keyspace{ | ||
| Name: keyspaceUnshardedName, | ||
| SchemaSQL: sqlSchema, | ||
| } | ||
| if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 1, false); err != nil { | ||
| return nil, 1 | ||
| } | ||
|
|
||
| clusterInstance.VtGateExtraArgs = []string{ | ||
| "-mysql_auth_server_static_file", clusterInstance.TmpDirectory + "/" + mysqlAuthServerStatic, | ||
| "-keyspaces_to_watch", "ks1", | ||
| } | ||
|
|
||
| // Start vtgate | ||
| if err := clusterInstance.StartVtgate(); err != nil { | ||
| return nil, 1 | ||
| } | ||
| vtParams = mysql.ConnParams{ | ||
| Host: clusterInstance.Hostname, | ||
| Port: clusterInstance.VtgateMySQLPort, | ||
| } | ||
| rand.Seed(time.Now().UnixNano()) | ||
| return clusterInstance, 0 | ||
| } | ||
|
|
||
| func TestRoutingWithKeyspacesToWatch(t *testing.T) { | ||
| defer cluster.PanicHandler(t) | ||
|
|
||
| clusterInstance, exitCode := createCluster() | ||
| defer clusterInstance.Teardown() | ||
|
|
||
| if exitCode != 0 { | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| dsn := fmt.Sprintf( | ||
| "testuser1:testpassword1@tcp(%s:%v)/", | ||
| clusterInstance.Hostname, | ||
| clusterInstance.VtgateMySQLPort, | ||
| ) | ||
| db, err := sql.Open("mysql", dsn) | ||
| require.Nil(t, err) | ||
| defer db.Close() | ||
|
|
||
| // if this returns w/o failing the test we're good to go | ||
| _, err = db.Exec("select * from keyspaces_to_watch_test") | ||
| require.Nil(t, err) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: phrasing.
"Unable to apply DDL because toposerver is read-only..." might be better?