Browse Source

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

pull/6319/head
Sam Kleinman 4 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" "bytes"
"context" "context"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -704,7 +705,10 @@ func randConsensusState(
css := make([]*State, nValidators) css := make([]*State, nValidators)
logger := consensusLogger() logger := consensusLogger()
closeFuncs := make([]func() error, 0, nValidators)
configRootDirs := make([]string, 0, nValidators) configRootDirs := make([]string, 0, nValidators)
for i := 0; i < nValidators; i++ { for i := 0; i < nValidators; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB) stateStore := sm.NewStore(stateDB)
@ -719,6 +723,11 @@ func randConsensusState(
ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
app := appFunc() app := appFunc()
if appCloser, ok := app.(io.Closer); ok {
closeFuncs = append(closeFuncs, appCloser.Close)
}
vals := types.TM2PB.ValidatorUpdates(state.Validators) vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals}) app.InitChain(abci.RequestInitChain{Validators: vals})
@ -728,6 +737,9 @@ func randConsensusState(
} }
return css, func() { return css, func() {
for _, closer := range closeFuncs {
_ = closer()
}
for _, dir := range configRootDirs { for _, dir := range configRootDirs {
os.RemoveAll(dir) 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) // 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) proxyApp := proxy.NewAppConns(clientCreator)
err = proxyApp.Start() err = proxyApp.Start()
if err != nil { 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 { } else {
pval = nil pval = nil
} }
appClient, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
return NewNode(config, return NewNode(config,
pval, pval,
nodeKey, nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config), DefaultGenesisDocProviderFunc(config),
DefaultDBProvider, DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation), 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()) pval, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
require.NoError(t, err) require.NoError(t, err)
appClient, closer := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
t.Cleanup(func() { closer.Close() })
n, err := NewNode(config, n, err := NewNode(config,
pval, pval,
nodeKey, nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config), DefaultGenesisDocProviderFunc(config),
DefaultDBProvider, DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation), DefaultMetricsProvider(config.Instrumentation),


+ 16
- 7
proxy/client.go View File

@ -2,6 +2,7 @@ package proxy
import ( import (
"fmt" "fmt"
"io"
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/counter" "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 // DefaultClientCreator returns a default ClientCreator, which will create a
// local client if addr is one of: 'counter', 'counter_serial', 'kvstore', // local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
// 'persistent_kvstore' or 'noop', otherwise - a remote client. // '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 { switch addr {
case "counter": case "counter":
return NewLocalClientCreator(counter.NewApplication(false))
return NewLocalClientCreator(counter.NewApplication(false)), noopCloser{}
case "counter_serial": case "counter_serial":
return NewLocalClientCreator(counter.NewApplication(true))
return NewLocalClientCreator(counter.NewApplication(true)), noopCloser{}
case "kvstore": case "kvstore":
return NewLocalClientCreator(kvstore.NewApplication())
return NewLocalClientCreator(kvstore.NewApplication()), noopCloser{}
case "persistent_kvstore": case "persistent_kvstore":
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
app := kvstore.NewPersistentKVStoreApplication(dbDir)
return NewLocalClientCreator(app), app
case "noop": case "noop":
return NewLocalClientCreator(types.NewBaseApplication())
return NewLocalClientCreator(types.NewBaseApplication()), noopCloser{}
default: default:
mustConnect := false // loop retrying 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 // and shut down proper at the end
rpctest.StopTendermint(node) rpctest.StopTendermint(node)
app.Close()
_ = os.RemoveAll(dir) _ = os.RemoveAll(dir)
os.Exit(code) os.Exit(code)
} }

Loading…
Cancel
Save