Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: zhangwenkang <zwenkang@vmware.com>
  • Loading branch information
kensou97 committed Jul 1, 2023
1 parent 207ccf2 commit e7f124f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/integration/clientv3/experimental/recipes/v3_barrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Fatalf("barrier timed out")
case <-donec:
}
}
}

0 comments on commit e7f124f

Please sign in to comment.