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])
|
q.Push(&items[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
var lock sync.Mutex
|
var (
|
||||||
stopCh := make(chan chan struct{})
|
lock sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
stopCh = make(chan chan struct{})
|
||||||
|
)
|
||||||
|
defer wg.Wait()
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-clock.After(testQueueRefresh):
|
case <-clock.After(testQueueRefresh):
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
q.Refresh()
|
q.Refresh()
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
case stop := <-stopCh:
|
case <-stopCh:
|
||||||
close(stop)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,9 +109,8 @@ func TestLazyQueue(t *testing.T) {
|
||||||
if rand.Intn(100) == 0 {
|
if rand.Intn(100) == 0 {
|
||||||
p := q.PopItem().(*lazyItem)
|
p := q.PopItem().(*lazyItem)
|
||||||
if p.p != maxPri {
|
if p.p != maxPri {
|
||||||
stop := make(chan struct{})
|
|
||||||
stopCh <- stop // No need to wait for `<-stop`. test failed anyway
|
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
close(stopCh)
|
||||||
t.Fatalf("incorrect item (best known priority %d, popped %d)", maxPri, p.p)
|
t.Fatalf("incorrect item (best known priority %d, popped %d)", maxPri, p.p)
|
||||||
}
|
}
|
||||||
q.Push(p)
|
q.Push(p)
|
||||||
|
|
@ -116,7 +120,5 @@ func TestLazyQueue(t *testing.T) {
|
||||||
clock.WaitForTimers(1)
|
clock.WaitForTimers(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
stop := make(chan struct{})
|
close(stopCh)
|
||||||
stopCh <- stop
|
|
||||||
<-stop
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue