Browse Source

test: improve cleanup for data and disk use (#6311)

pull/6319/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
6d9372bd39
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 10 deletions
  1. +12
    -0
      consensus/common_test.go
  2. +1
    -1
      consensus/replay_file.go
  3. +3
    -1
      node/node.go
  4. +3
    -1
      node/node_test.go
  5. +16
    -7
      proxy/client.go
  6. +1
    -0
      rpc/client/main_test.go

+ 12
- 0
consensus/common_test.go View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -704,7 +705,10 @@ func randConsensusState(
css := make([]*State, nValidators)
logger := consensusLogger()
closeFuncs := make([]func() error, 0, nValidators)
configRootDirs := make([]string, 0, nValidators)
for i := 0; i < nValidators; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
@ -719,6 +723,11 @@ func randConsensusState(
ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
app := appFunc()
if appCloser, ok := app.(io.Closer); ok {
closeFuncs = append(closeFuncs, appCloser.Close)
}
vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})
@ -728,6 +737,9 @@ func randConsensusState(
}
return css, func() {
for _, closer := range closeFuncs {
_ = closer()
}
for _, dir := range configRootDirs {
os.RemoveAll(dir)
}


+ 1
- 1
consensus/replay_file.go View File

@ -308,7 +308,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
}
// Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
clientCreator, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
proxyApp := proxy.NewAppConns(clientCreator)
err = proxyApp.Start()
if err != nil {


+ 3
- 1
node/node.go View File

@ -126,10 +126,12 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
} else {
pval = nil
}
appClient, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
return NewNode(config,
pval,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation),


+ 3
- 1
node/node_test.go View File

@ -499,10 +499,12 @@ func TestNodeNewNodeCustomReactors(t *testing.T) {
pval, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
require.NoError(t, err)
appClient, closer := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
t.Cleanup(func() { closer.Close() })
n, err := NewNode(config,
pval,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation),


+ 16
- 7
proxy/client.go View File

@ -2,6 +2,7 @@ package proxy
import (
"fmt"
"io"
abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/counter"
@ -69,20 +70,28 @@ func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
// DefaultClientCreator returns a default ClientCreator, which will create a
// local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
// 'persistent_kvstore' or 'noop', otherwise - a remote client.
func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
//
// The Closer is a noop except for persistent_kvstore applications,
// which will clean up the store.
func DefaultClientCreator(addr, transport, dbDir string) (ClientCreator, io.Closer) {
switch addr {
case "counter":
return NewLocalClientCreator(counter.NewApplication(false))
return NewLocalClientCreator(counter.NewApplication(false)), noopCloser{}
case "counter_serial":
return NewLocalClientCreator(counter.NewApplication(true))
return NewLocalClientCreator(counter.NewApplication(true)), noopCloser{}
case "kvstore":
return NewLocalClientCreator(kvstore.NewApplication())
return NewLocalClientCreator(kvstore.NewApplication()), noopCloser{}
case "persistent_kvstore":
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
app := kvstore.NewPersistentKVStoreApplication(dbDir)
return NewLocalClientCreator(app), app
case "noop":
return NewLocalClientCreator(types.NewBaseApplication())
return NewLocalClientCreator(types.NewBaseApplication()), noopCloser{}
default:
mustConnect := false // loop retrying
return NewRemoteClientCreator(addr, transport, mustConnect)
return NewRemoteClientCreator(addr, transport, mustConnect), noopCloser{}
}
}
type noopCloser struct{}
func (noopCloser) Close() error { return nil }

+ 1
- 0
rpc/client/main_test.go View File

@ -26,6 +26,7 @@ func TestMain(m *testing.M) {
// and shut down proper at the end
rpctest.StopTendermint(node)
app.Close()
_ = os.RemoveAll(dir)
os.Exit(code)
}

Loading…
Cancel
Save