forked from cerc-io/plugeth
les: fix goroutine leaks in tests (#22707)
This commit is contained in:
parent
96828c90f5
commit
3e68d627b1
@ -212,17 +212,25 @@ func (s *LesServer) Stop() error {
|
|||||||
close(s.closeCh)
|
close(s.closeCh)
|
||||||
|
|
||||||
s.clientPool.Stop()
|
s.clientPool.Stop()
|
||||||
s.serverset.close()
|
if s.serverset != nil {
|
||||||
|
s.serverset.close()
|
||||||
|
}
|
||||||
s.peers.close()
|
s.peers.close()
|
||||||
s.fcManager.Stop()
|
s.fcManager.Stop()
|
||||||
s.costTracker.stop()
|
s.costTracker.stop()
|
||||||
s.handler.stop()
|
s.handler.stop()
|
||||||
s.servingQueue.stop()
|
s.servingQueue.stop()
|
||||||
s.vfluxServer.Stop()
|
if s.vfluxServer != nil {
|
||||||
|
s.vfluxServer.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
// Note, bloom trie indexer is closed by parent bloombits indexer.
|
// Note, bloom trie indexer is closed by parent bloombits indexer.
|
||||||
s.chtIndexer.Close()
|
if s.chtIndexer != nil {
|
||||||
s.lesDb.Close()
|
s.chtIndexer.Close()
|
||||||
|
}
|
||||||
|
if s.lesDb != nil {
|
||||||
|
s.lesDb.Close()
|
||||||
|
}
|
||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
log.Info("Les server stopped")
|
log.Info("Les server stopped")
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ func testIndexers(db ethdb.Database, odr light.OdrBackend, config *light.Indexer
|
|||||||
return indexers[:]
|
return indexers[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, indexers []*core.ChainIndexer, db ethdb.Database, peers *serverPeerSet, ulcServers []string, ulcFraction int) *clientHandler {
|
func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, indexers []*core.ChainIndexer, db ethdb.Database, peers *serverPeerSet, ulcServers []string, ulcFraction int) (*clientHandler, func()) {
|
||||||
var (
|
var (
|
||||||
evmux = new(event.TypeMux)
|
evmux = new(event.TypeMux)
|
||||||
engine = ethash.NewFaker()
|
engine = ethash.NewFaker()
|
||||||
@ -245,10 +245,12 @@ func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, index
|
|||||||
client.oracle.Start(backend)
|
client.oracle.Start(backend)
|
||||||
}
|
}
|
||||||
client.handler.start()
|
client.handler.start()
|
||||||
return client.handler
|
return client.handler, func() {
|
||||||
|
client.handler.stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Database, clock mclock.Clock) (*serverHandler, *backends.SimulatedBackend) {
|
func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Database, clock mclock.Clock) (*serverHandler, *backends.SimulatedBackend, func()) {
|
||||||
var (
|
var (
|
||||||
gspec = core.Genesis{
|
gspec = core.Genesis{
|
||||||
Config: params.AllEthashProtocolChanges,
|
Config: params.AllEthashProtocolChanges,
|
||||||
@ -314,7 +316,8 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da
|
|||||||
}
|
}
|
||||||
server.servingQueue.setThreads(4)
|
server.servingQueue.setThreads(4)
|
||||||
server.handler.start()
|
server.handler.start()
|
||||||
return server.handler, simulation
|
closer := func() { server.Stop() }
|
||||||
|
return server.handler, simulation, closer
|
||||||
}
|
}
|
||||||
|
|
||||||
func alwaysTrueFn() bool {
|
func alwaysTrueFn() bool {
|
||||||
@ -600,8 +603,8 @@ func newClientServerEnv(t *testing.T, config testnetConfig) (*testServer, *testC
|
|||||||
ccIndexer, cbIndexer, cbtIndexer := cIndexers[0], cIndexers[1], cIndexers[2]
|
ccIndexer, cbIndexer, cbtIndexer := cIndexers[0], cIndexers[1], cIndexers[2]
|
||||||
odr.SetIndexers(ccIndexer, cbIndexer, cbtIndexer)
|
odr.SetIndexers(ccIndexer, cbIndexer, cbtIndexer)
|
||||||
|
|
||||||
server, b := newTestServerHandler(config.blocks, sindexers, sdb, clock)
|
server, b, serverClose := newTestServerHandler(config.blocks, sindexers, sdb, clock)
|
||||||
client := newTestClientHandler(b, odr, cIndexers, cdb, speers, config.ulcServers, config.ulcFraction)
|
client, clientClose := newTestClientHandler(b, odr, cIndexers, cdb, speers, config.ulcServers, config.ulcFraction)
|
||||||
|
|
||||||
scIndexer.Start(server.blockchain)
|
scIndexer.Start(server.blockchain)
|
||||||
sbIndexer.Start(server.blockchain)
|
sbIndexer.Start(server.blockchain)
|
||||||
@ -658,7 +661,10 @@ func newClientServerEnv(t *testing.T, config testnetConfig) (*testServer, *testC
|
|||||||
cbIndexer.Close()
|
cbIndexer.Close()
|
||||||
scIndexer.Close()
|
scIndexer.Close()
|
||||||
sbIndexer.Close()
|
sbIndexer.Close()
|
||||||
|
dist.close()
|
||||||
|
serverClose()
|
||||||
b.Close()
|
b.Close()
|
||||||
|
clientClose()
|
||||||
}
|
}
|
||||||
return s, c, teardown
|
return s, c, teardown
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user