Skip to content
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

Wrangler tests: Return a fake tablet in the wrangler test dialer to avoid tablet picker errors spamming the test logs #7863

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions go/vt/wrangler/wrangler_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func init() {
tabletconn.RegisterDialer("WranglerTest", func(tablet *topodatapb.Tablet, failFast grpcclient.FailFast) (queryservice.QueryService, error) {
wranglerEnv.mu.Lock()
defer wranglerEnv.mu.Unlock()
fmt.Println("In WranglerTest dialer")
if qs, ok := wranglerEnv.tablets[int(tablet.Alias.Uid)]; ok {
fmt.Printf("query service is %v", qs)
return qs, nil
}
return nil, fmt.Errorf("tablet %d not found", tablet.Alias.Uid)
// some tests don't require the query service. Earlier we were returning an error for such cases but the tablet picker
// now logs a warning and spams the logs. Hence we return a fake service instead
return newFakeTestWranglerTablet(), nil
})
}

Expand Down Expand Up @@ -211,6 +211,24 @@ func (env *testWranglerEnv) close() {
env.tablets = nil
}

func newFakeTestWranglerTablet() *testWranglerTablet {
id := 999
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "fake",
Uid: uint32(id),
},
Keyspace: "fake",
Shard: "fake",
KeyRange: &topodatapb.KeyRange{},
Type: topodatapb.TabletType_MASTER,
PortMap: map[string]int32{
"test": int32(id),
},
}
return newTestWranglerTablet(tablet)
}

func (env *testWranglerEnv) addTablet(id int, keyspace, shard string, tabletType topodatapb.TabletType) *testWranglerTablet {
env.mu.Lock()
defer env.mu.Unlock()
Expand Down Expand Up @@ -316,13 +334,12 @@ func (tmc *testWranglerTMClient) VReplicationExec(ctx context.Context, tablet *t
}

func (tmc *testWranglerTMClient) ExecuteFetchAsApp(ctx context.Context, tablet *topodatapb.Tablet, usePool bool, query []byte, maxRows int) (*querypb.QueryResult, error) {
// fmt.Printf("tablet: %d query: %s\n", tablet.Alias.Uid, string(query))
t := wranglerEnv.tablets[int(tablet.Alias.Uid)]
t.gotQueries = append(t.gotQueries, string(query))
result, ok := t.queryResults[string(query)]
if !ok {
result = &querypb.QueryResult{}
log.Errorf("QUery: %s, Result :%v\n", query, result)
log.Errorf("Query: %s, Result :%v\n", query, result)
}
return result, nil
}