mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
common/prque: use waitgroup in test
This commit is contained in:
parent
baef1b6b5e
commit
a9fc6b7bb8
1 changed files with 11 additions and 9 deletions
|
|
@ -74,17 +74,22 @@ func TestLazyQueue(t *testing.T) {
|
|||
q.Push(&items[i])
|
||||
}
|
||||
|
||||
var lock sync.Mutex
|
||||
stopCh := make(chan chan struct{})
|
||||
var (
|
||||
lock sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
stopCh = make(chan chan struct{})
|
||||
)
|
||||
defer wg.Wait()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-clock.After(testQueueRefresh):
|
||||
lock.Lock()
|
||||
q.Refresh()
|
||||
lock.Unlock()
|
||||
case stop := <-stopCh:
|
||||
close(stop)
|
||||
case <-stopCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -104,9 +109,8 @@ func TestLazyQueue(t *testing.T) {
|
|||
if rand.Intn(100) == 0 {
|
||||
p := q.PopItem().(*lazyItem)
|
||||
if p.p != maxPri {
|
||||
stop := make(chan struct{})
|
||||
stopCh <- stop // No need to wait for `<-stop`. test failed anyway
|
||||
lock.Unlock()
|
||||
close(stopCh)
|
||||
t.Fatalf("incorrect item (best known priority %d, popped %d)", maxPri, p.p)
|
||||
}
|
||||
q.Push(p)
|
||||
|
|
@ -116,7 +120,5 @@ func TestLazyQueue(t *testing.T) {
|
|||
clock.WaitForTimers(1)
|
||||
}
|
||||
|
||||
stop := make(chan struct{})
|
||||
stopCh <- stop
|
||||
<-stop
|
||||
close(stopCh)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue