Skip to content

Commit

Permalink
Merge pull request #7869 from heyitsanthony/fix-lease-require-leader-…
Browse files Browse the repository at this point in the history
…test

clientv3/integration: drain keepalives before waiting for leader loss
  • Loading branch information
Anthony Romano committed May 4, 2017
2 parents 7f05e22 + f6d0dda commit 2e32d21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clientv3/integration/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ func TestLeaseWithRequireLeader(t *testing.T) {
}

clus.Members[1].Stop(t)
// kaReqLeader may issue multiple requests while waiting for the first
// response from proxy server; drain any stray keepalive responses
time.Sleep(100 * time.Millisecond)
for len(kaReqLeader) > 0 {
<-kaReqLeader
}

select {
case resp, ok := <-kaReqLeader:
Expand Down
4 changes: 4 additions & 0 deletions integration/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type proxyCloser struct {
clientv3.Watcher
wdonec <-chan struct{}
kvdonec <-chan struct{}
lclose func()
lpdonec <-chan struct{}
}

Expand All @@ -83,6 +84,7 @@ func (pc *proxyCloser) Close() error {
<-pc.kvdonec
err := pc.Watcher.Close()
<-pc.wdonec
pc.lclose()
<-pc.lpdonec
return err
}
Expand All @@ -95,11 +97,13 @@ func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) {
rpc := toGRPC(c)
c.KV = clientv3.NewKVFromKVClient(rpc.KV)
pmu.Lock()
lc := c.Lease
c.Lease = clientv3.NewLeaseFromLeaseClient(rpc.Lease, cfg.DialTimeout)
c.Watcher = &proxyCloser{
Watcher: clientv3.NewWatchFromWatchClient(rpc.Watch),
wdonec: proxies[c].wdonec,
kvdonec: proxies[c].kvdonec,
lclose: func() { lc.Close() },
lpdonec: proxies[c].lpdonec,
}
pmu.Unlock()
Expand Down

0 comments on commit 2e32d21

Please sign in to comment.