Skip to content

Commit

Permalink
test(572): fix flaky test with TestSecondaryIndices_List (#595)
Browse files Browse the repository at this point in the history
Before fix,when run with `go test -timeout 10m -run
^TestSecondaryIndices_List$ github.com/streamnative/oxia/server -gcflags
all='-N' -v -count=10000`, the flaky test reproduced.

After fix, run multi times tests without fail.

fix: #582
  • Loading branch information
lsytj0413 authored Jan 21, 2025
1 parent 89ee466 commit 11e8833
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions server/secondary_indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func TestSecondaryIndices_List(t *testing.T) {
assert.Equal(t, "/b", k)
k = <-strCh
assert.Equal(t, "/c", k)
assert.Empty(t, strCh)
// NOTE: we cannot use assert.Empty to check strCh and must to validate it's closed, because when there is no more
// items to return, assert.Empty will passthrough and leave the iterator opened.
_, ok := <-strCh
assert.False(t, ok)

// Wrong index
strCh, err = lc.List(context.Background(), &proto.ListRequest{
Expand All @@ -75,7 +78,8 @@ func TestSecondaryIndices_List(t *testing.T) {
SecondaryIndexName: pb.String("wrong-idx"),
})
assert.NoError(t, err)
assert.Empty(t, strCh)
_, ok = <-strCh
assert.False(t, ok)

// Individual delete
_, err = lc.Write(context.Background(), &proto.WriteRequest{
Expand All @@ -99,8 +103,8 @@ func TestSecondaryIndices_List(t *testing.T) {
assert.Equal(t, "/d", k)
k = <-strCh
assert.Equal(t, "/e", k)

assert.Empty(t, strCh)
_, ok = <-strCh
assert.False(t, ok)

// Range delete
_, err = lc.Write(context.Background(), &proto.WriteRequest{
Expand All @@ -124,7 +128,8 @@ func TestSecondaryIndices_List(t *testing.T) {
assert.Equal(t, "/d", k)
k = <-strCh
assert.Equal(t, "/e", k)
assert.Empty(t, strCh)
_, ok = <-strCh
assert.False(t, ok)

assert.NoError(t, lc.Close())
assert.NoError(t, kvFactory.Close())
Expand Down

0 comments on commit 11e8833

Please sign in to comment.