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

tests: move some client tests to integration test package #1118

Merged
merged 4 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 18 additions & 6 deletions pd-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (c *client) tsLoop() {
stream, err = c.leaderClient().Tso(ctx)
if err != nil {
log.Errorf("[pd] create tso stream error: %v", err)
c.scheduleCheckLeader()
c.ScheduleCheckLeader()
cancel()
c.revokeTSORequest(err)
select {
Expand Down Expand Up @@ -389,7 +389,7 @@ func (c *client) tsLoop() {

if err != nil {
log.Errorf("[pd] getTS error: %v", err)
c.scheduleCheckLeader()
c.ScheduleCheckLeader()
cancel()
stream, cancel = nil, nil
}
Expand Down Expand Up @@ -482,7 +482,7 @@ func (c *client) leaderClient() pdpb.PDClient {
return pdpb.NewPDClient(c.connMu.clientConns[c.connMu.leader])
}

func (c *client) scheduleCheckLeader() {
func (c *client) ScheduleCheckLeader() {
select {
case c.checkLeaderCh <- struct{}{}:
default:
Expand All @@ -493,6 +493,18 @@ func (c *client) GetClusterID(context.Context) uint64 {
return c.clusterID
}

// For testing use.
func (c *client) GetLeaderAddr() string {
c.connMu.RLock()
defer c.connMu.RUnlock()
return c.connMu.leader
}

// For testing use. It should only be called when the client is closed.
func (c *client) GetURLs() []string {
return c.urls
}

var tsoReqPool = sync.Pool{
New: func() interface{} {
return &tsoRequest{
Expand Down Expand Up @@ -561,7 +573,7 @@ func (c *client) GetRegion(ctx context.Context, key []byte) (*metapb.Region, *me

if err != nil {
cmdFailedDuration.WithLabelValues("get_region").Observe(time.Since(start).Seconds())
c.scheduleCheckLeader()
c.ScheduleCheckLeader()
return nil, nil, errors.Trace(err)
}
return resp.GetRegion(), resp.GetLeader(), nil
Expand All @@ -585,7 +597,7 @@ func (c *client) GetRegionByID(ctx context.Context, regionID uint64) (*metapb.Re

if err != nil {
cmdFailedDuration.WithLabelValues("get_region_byid").Observe(time.Since(start).Seconds())
c.scheduleCheckLeader()
c.ScheduleCheckLeader()
return nil, nil, errors.Trace(err)
}
return resp.GetRegion(), resp.GetLeader(), nil
Expand All @@ -609,7 +621,7 @@ func (c *client) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, e

if err != nil {
cmdFailedDuration.WithLabelValues("get_store").Observe(time.Since(start).Seconds())
c.scheduleCheckLeader()
c.ScheduleCheckLeader()
return nil, errors.Trace(err)
}
store := resp.GetStore()
Expand Down
237 changes: 0 additions & 237 deletions pd-client/leader_change_test.go

This file was deleted.

Loading