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.5 test: fix TestHashKVWhenCompacting: ensure all goroutine finished #17320

Merged
Merged
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
24 changes: 22 additions & 2 deletions 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 @@ -594,9 +599,20 @@ func TestHashKVWhenCompacting(t *testing.T) {
}()

// Compact the store in a goroutine, using revision 9900 to 10000 and close donec when finished
wg.Add(1)
go func() {
defer close(donec)
defer func() {
close(donec)
wg.Done()
}()

for i := 100; i >= 0; i-- {
select {
case <-stopc:
return
default:
}

_, err := s.Compact(traceutil.TODO(), int64(rev-i))
if err != nil {
t.Error(err)
Expand All @@ -610,10 +626,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
Loading