File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -551,6 +551,7 @@ func TestHashKVWhenCompacting(t *testing.T) {
551551 hashCompactc := make (chan hashKVResult , 1 )
552552 var wg sync.WaitGroup
553553 donec := make (chan struct {})
554+ stopc := make (chan struct {})
554555
555556 // Call HashByRev(10000) in multiple goroutines until donec is closed
556557 for i := 0 ; i < 10 ; i ++ {
@@ -563,6 +564,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
563564 t .Error (err )
564565 }
565566 select {
567+ case <- stopc :
568+ return
566569 case <- donec :
567570 return
568571 case hashCompactc <- hashKVResult {hash .Hash , hash .CompactRevision }:
@@ -586,6 +589,8 @@ func TestHashKVWhenCompacting(t *testing.T) {
586589 }
587590
588591 select {
592+ case <- stopc :
593+ return
589594 case <- donec :
590595 return
591596 default :
@@ -594,9 +599,20 @@ func TestHashKVWhenCompacting(t *testing.T) {
594599 }()
595600
596601 // Compact the store in a goroutine, using revision 9900 to 10000 and close donec when finished
602+ wg .Add (1 )
597603 go func () {
598- defer close (donec )
604+ defer func () {
605+ close (donec )
606+ wg .Done ()
607+ }()
608+
599609 for i := 100 ; i >= 0 ; i -- {
610+ select {
611+ case <- stopc :
612+ return
613+ default :
614+ }
615+
600616 _ , err := s .Compact (traceutil .TODO (), int64 (rev - i ))
601617 if err != nil {
602618 t .Error (err )
@@ -610,10 +626,14 @@ func TestHashKVWhenCompacting(t *testing.T) {
610626
611627 select {
612628 case <- donec :
613- wg .Wait ()
614629 case <- time .After (10 * time .Second ):
630+ close (stopc )
631+ wg .Wait ()
615632 testutil .FatalStack (t , "timeout" )
616633 }
634+
635+ close (stopc )
636+ wg .Wait ()
617637}
618638
619639// TestHashKVWithCompactedAndFutureRevisions ensures that HashKV returns a correct hash when called
You can’t perform that action at this time.
0 commit comments