Merge pull request #17320 from ahrtr/3.5_TestHashKVWhenCompacting_20240125
[3.5 test: fix `TestHashKVWhenCompacting`: ensure all goroutine finished
This commit is contained in:
commit
141232e773
@ -551,6 +551,7 @@ func TestHashKVWhenCompacting(t *testing.T) {
|
|||||||
hashCompactc := make(chan hashKVResult, 1)
|
hashCompactc := make(chan hashKVResult, 1)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
donec := make(chan struct{})
|
donec := make(chan struct{})
|
||||||
|
stopc := make(chan struct{})
|
||||||
|
|
||||||
// Call HashByRev(10000) in multiple goroutines until donec is closed
|
// Call HashByRev(10000) in multiple goroutines until donec is closed
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
@ -563,6 +564,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
case <-stopc:
|
||||||
|
return
|
||||||
case <-donec:
|
case <-donec:
|
||||||
return
|
return
|
||||||
case hashCompactc <- hashKVResult{hash.Hash, hash.CompactRevision}:
|
case hashCompactc <- hashKVResult{hash.Hash, hash.CompactRevision}:
|
||||||
@ -586,6 +589,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
case <-stopc:
|
||||||
|
return
|
||||||
case <-donec:
|
case <-donec:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
@ -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
|
// Compact the store in a goroutine, using revision 9900 to 10000 and close donec when finished
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(donec)
|
defer func() {
|
||||||
|
close(donec)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
for i := 100; i >= 0; i-- {
|
for i := 100; i >= 0; i-- {
|
||||||
|
select {
|
||||||
|
case <-stopc:
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
_, err := s.Compact(traceutil.TODO(), int64(rev-i))
|
_, err := s.Compact(traceutil.TODO(), int64(rev-i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -610,10 +626,14 @@ func TestHashKVWhenCompacting(t *testing.T) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-donec:
|
case <-donec:
|
||||||
wg.Wait()
|
|
||||||
case <-time.After(10 * time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
|
close(stopc)
|
||||||
|
wg.Wait()
|
||||||
testutil.FatalStack(t, "timeout")
|
testutil.FatalStack(t, "timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(stopc)
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestHashKVWithCompactedAndFutureRevisions ensures that HashKV returns a correct hash when called
|
// TestHashKVWithCompactedAndFutureRevisions ensures that HashKV returns a correct hash when called
|
||||||
|
Loading…
Reference in New Issue
Block a user