eth/fetcher, trie: unit test reliability fixes (#23020)
Some tests take quite some time during exit, which I think causes some appveyor fails like this: https://ci.appveyor.com/project/ethereum/go-ethereum/builds/39511210/job/xhom84eg2e4uulq3 One of the things that seem to take time during exit is waiting (up to 100ms) for the syncbloom to close. This PR changes it to use a channel, instead of looping with a 100ms wait. This also includes some unrelated changes improving the reliability of eth/fetcher tests, which fail a lot because they are time-dependent.
This commit is contained in:
committed by
GitHub
parent
686b2884ee
commit
c131e812ae
@ -45,11 +45,12 @@ var (
|
||||
// provided disk database on creation in a background thread and will only start
|
||||
// returning live results once that's finished.
|
||||
type SyncBloom struct {
|
||||
bloom *bloomfilter.Filter
|
||||
inited uint32
|
||||
closer sync.Once
|
||||
closed uint32
|
||||
pend sync.WaitGroup
|
||||
bloom *bloomfilter.Filter
|
||||
inited uint32
|
||||
closer sync.Once
|
||||
closed uint32
|
||||
pend sync.WaitGroup
|
||||
closeCh chan struct{}
|
||||
}
|
||||
|
||||
// NewSyncBloom creates a new bloom filter of the given size (in megabytes) and
|
||||
@ -64,7 +65,8 @@ func NewSyncBloom(memory uint64, database ethdb.Iteratee) *SyncBloom {
|
||||
|
||||
// Assemble the fast sync bloom and init it from previous sessions
|
||||
b := &SyncBloom{
|
||||
bloom: bloom,
|
||||
bloom: bloom,
|
||||
closeCh: make(chan struct{}),
|
||||
}
|
||||
b.pend.Add(2)
|
||||
go func() {
|
||||
@ -125,16 +127,15 @@ func (b *SyncBloom) init(database ethdb.Iteratee) {
|
||||
// meter periodically recalculates the false positive error rate of the bloom
|
||||
// filter and reports it in a metric.
|
||||
func (b *SyncBloom) meter() {
|
||||
// check every second
|
||||
tick := time.NewTicker(1 * time.Second)
|
||||
for {
|
||||
// Report the current error ration. No floats, lame, scale it up.
|
||||
bloomErrorGauge.Update(int64(b.bloom.FalsePosititveProbability() * 100000))
|
||||
|
||||
// Wait one second, but check termination more frequently
|
||||
for i := 0; i < 10; i++ {
|
||||
if atomic.LoadUint32(&b.closed) == 1 {
|
||||
return
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
select {
|
||||
case <-tick.C:
|
||||
// Report the current error ration. No floats, lame, scale it up.
|
||||
bloomErrorGauge.Update(int64(b.bloom.FalsePosititveProbability() * 100000))
|
||||
case <-b.closeCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,6 +146,7 @@ func (b *SyncBloom) Close() error {
|
||||
b.closer.Do(func() {
|
||||
// Ensure the initializer is stopped
|
||||
atomic.StoreUint32(&b.closed, 1)
|
||||
close(b.closeCh)
|
||||
b.pend.Wait()
|
||||
|
||||
// Wipe the bloom, but mark it "uninited" just in case someone attempts an access
|
||||
|
Reference in New Issue
Block a user