Skip to content

Commit

Permalink
test: fix TestHashKVWhenCompacting: ensure all goroutine finished
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 25, 2024
1 parent a0ff8e4 commit 2706dc0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/mvcc/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ func TestHashKVWhenCompacting(t *testing.T) {
hashCompactc := make(chan hashKVResult, 1)
var wg sync.WaitGroup
donec := make(chan struct{})
stopc := make(chan struct{})

// Call HashByRev(10000) in multiple goroutines until donec is closed
for i := 0; i < 10; i++ {
Expand All @@ -563,6 +564,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
t.Error(err)
}
select {
case <-stopc:
return
case <-donec:
return
case hashCompactc <- hashKVResult{hash.Hash, hash.CompactRevision}:
Expand All @@ -586,6 +589,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
}

select {
case <-stopc:
return
case <-donec:
return
default:
Expand All @@ -610,10 +615,14 @@ func TestHashKVWhenCompacting(t *testing.T) {

select {
case <-donec:
wg.Wait()
case <-time.After(10 * time.Second):
close(stopc)
wg.Wait()
testutil.FatalStack(t, "timeout")
}

close(stopc)
wg.Wait()
}

// TestHashKVWithCompactedAndFutureRevisions ensures that HashKV returns a correct hash when called
Expand Down

0 comments on commit 2706dc0

Please sign in to comment.