mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: remove v3.WithFirstKey() in Barrier.Wait()
fix the unexpected blocking when using Barrier.Wait(), e.g. NewBarrier(client, "a").Wait() will block if key "a" is not existed but "a0" is existed, but it should return immediately. Signed-off-by: zhangwenkang <zwenkang@vmware.com>
This commit is contained in:
@@ -83,3 +83,42 @@ func testBarrier(t *testing.T, waiters int, chooseClient func() *clientv3.Client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBarrierWaitNonexistentKey(t *testing.T) {
|
||||
integration2.BeforeTest(t)
|
||||
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
|
||||
defer clus.Terminate(t)
|
||||
cli := clus.Client(0)
|
||||
|
||||
if _, err := cli.Put(cli.Ctx(), "test-barrier-0", ""); err != nil {
|
||||
t.Errorf("could not put test-barrier0, err:%v", err)
|
||||
}
|
||||
|
||||
donec := make(chan struct{})
|
||||
stopc := make(chan struct{})
|
||||
defer close(stopc)
|
||||
|
||||
waiters := 5
|
||||
for i := 0; i < waiters; i++ {
|
||||
go func() {
|
||||
br := recipe.NewBarrier(cli, "test-barrier")
|
||||
if err := br.Wait(); err != nil {
|
||||
t.Errorf("could not wait on barrier (%v)", err)
|
||||
}
|
||||
select {
|
||||
case donec <- struct{}{}:
|
||||
case <-stopc:
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// all waiters should return immediately if waiting on a nonexistent key "test-barrier" even if key "test-barrier-0" exists
|
||||
timerC := time.After(time.Duration(waiters*100) * time.Millisecond)
|
||||
for i := 0; i < waiters; i++ {
|
||||
select {
|
||||
case <-timerC:
|
||||
t.Fatal("barrier timed out")
|
||||
case <-donec:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user