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

[3.4] Backport clientv3: remove v3.WithFirstKey() in Barrier.Wait() #16843

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion contrib/recipes/barrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (b *Barrier) Release() error {
// Wait blocks on the barrier key until it is deleted. If there is no key, Wait
// assumes Release has already been called and returns immediately.
func (b *Barrier) Wait() error {
resp, err := b.client.Get(b.ctx, b.key, v3.WithFirstKey()...)
resp, err := b.client.Get(b.ctx, b.key)
if err != nil {
return err
}
Expand Down
39 changes: 39 additions & 0 deletions integration/v3_barrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,42 @@ func testBarrier(t *testing.T, waiters int, chooseClient func() *clientv3.Client
}
}
}

func TestBarrierWaitNonexistentKey(t *testing.T) {
defer testutil.AfterTest(t)
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
defer clus.Terminate(t)
cli := clus.clients[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:
}
}
}
Loading