Skip to content

Commit

Permalink
Fixing flaky TestLeasingDeleteRangeContendTxn
Browse files Browse the repository at this point in the history
Fixes etcd-io#15352.
Depending on the goroutine scheduling, the expected count of 8 might not
have been reached yet. This ensures the routine won't stop earlier than
that.

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
  • Loading branch information
tjungblu committed Mar 3, 2023
1 parent d4acc0a commit 63964ec
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/integration/clientv3/lease/leasing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lease_test

import (
"context"
"errors"
"fmt"
"math/rand"
"reflect"
Expand Down Expand Up @@ -1270,7 +1271,8 @@ func testLeasingDeleteRangeContend(t *testing.T, op clientv3.Op) {
testutil.AssertNil(t, err)
defer closePutKV()

for i := 0; i < 8; i++ {
const maxKey = 8
for i := 0; i < maxKey; i++ {
key := fmt.Sprintf("key/%d", i)
if _, err = clus.Client(0).Put(context.TODO(), key, "123"); err != nil {
t.Fatal(err)
Expand All @@ -1282,14 +1284,17 @@ func testLeasingDeleteRangeContend(t *testing.T, op clientv3.Op) {

ctx, cancel := context.WithCancel(context.TODO())
donec := make(chan struct{})
go func() {
go func(t *testing.T) {
defer close(donec)
for i := 0; ctx.Err() == nil; i++ {
for i := 0; (i < maxKey) && (ctx.Err() == nil); i++ {
key := fmt.Sprintf("key/%d", i%8)
putkv.Put(ctx, key, "123")
putkv.Get(ctx, key)
if _, err = putkv.Put(ctx, key, "123"); err != nil {
if !errors.Is(err, context.Canceled) {
t.Errorf("fail putting key %s, err was: %v", key, err)
}
}
}
}()
}(t)

_, delErr := delkv.Do(context.TODO(), op)
cancel()
Expand All @@ -1299,7 +1304,7 @@ func testLeasingDeleteRangeContend(t *testing.T, op clientv3.Op) {
}

// confirm keys on non-deleter match etcd
for i := 0; i < 8; i++ {
for i := 0; i < maxKey; i++ {
key := fmt.Sprintf("key/%d", i)
resp, err := putkv.Get(context.TODO(), key)
if err != nil {
Expand Down

0 comments on commit 63964ec

Please sign in to comment.