mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
integration: fix TestElectionWait
elections are now per-session so waiting on the same election with the same client will not block like before Fixes #5362
This commit is contained in:
parent
deb21d3da5
commit
c21b885dd5
@ -19,6 +19,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/coreos/etcd/clientv3"
|
||||||
"github.com/coreos/etcd/clientv3/concurrency"
|
"github.com/coreos/etcd/clientv3/concurrency"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
@ -31,6 +32,8 @@ func TestElectionWait(t *testing.T) {
|
|||||||
|
|
||||||
leaders := 3
|
leaders := 3
|
||||||
followers := 3
|
followers := 3
|
||||||
|
var clients []*clientv3.Client
|
||||||
|
newClient := makeMultiNodeClients(t, clus.cluster, &clients)
|
||||||
|
|
||||||
electedc := make(chan string)
|
electedc := make(chan string)
|
||||||
nextc := []chan struct{}{}
|
nextc := []chan struct{}{}
|
||||||
@ -41,7 +44,7 @@ func TestElectionWait(t *testing.T) {
|
|||||||
nextc = append(nextc, make(chan struct{}))
|
nextc = append(nextc, make(chan struct{}))
|
||||||
go func(ch chan struct{}) {
|
go func(ch chan struct{}) {
|
||||||
for j := 0; j < leaders; j++ {
|
for j := 0; j < leaders; j++ {
|
||||||
b := concurrency.NewElection(clus.RandClient(), "test-election")
|
b := concurrency.NewElection(newClient(), "test-election")
|
||||||
cctx, cancel := context.WithCancel(context.TODO())
|
cctx, cancel := context.WithCancel(context.TODO())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
s, ok := <-b.Observe(cctx)
|
s, ok := <-b.Observe(cctx)
|
||||||
@ -59,7 +62,7 @@ func TestElectionWait(t *testing.T) {
|
|||||||
// elect some leaders
|
// elect some leaders
|
||||||
for i := 0; i < leaders; i++ {
|
for i := 0; i < leaders; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
e := concurrency.NewElection(clus.RandClient(), "test-election")
|
e := concurrency.NewElection(newClient(), "test-election")
|
||||||
ev := fmt.Sprintf("electval-%v", time.Now().UnixNano())
|
ev := fmt.Sprintf("electval-%v", time.Now().UnixNano())
|
||||||
if err := e.Campaign(context.TODO(), ev); err != nil {
|
if err := e.Campaign(context.TODO(), ev); err != nil {
|
||||||
t.Fatalf("failed volunteer (%v)", err)
|
t.Fatalf("failed volunteer (%v)", err)
|
||||||
@ -86,6 +89,8 @@ func TestElectionWait(t *testing.T) {
|
|||||||
for i := 0; i < followers; i++ {
|
for i := 0; i < followers; i++ {
|
||||||
<-donec
|
<-donec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeClients(t, clients)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestElectionFailover tests that an election will
|
// TestElectionFailover tests that an election will
|
||||||
|
Loading…
x
Reference in New Issue
Block a user