mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-10 05:50:19 +00:00
replace ResetTestRoot with SetupTestConfiguration in mempool and state
This commit is contained in:
@@ -11,8 +11,7 @@ import (
|
||||
func BenchmarkReap(b *testing.B) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(b, cc)
|
||||
|
||||
size := 10000
|
||||
for i := 0; i < size; i++ {
|
||||
@@ -31,8 +30,7 @@ func BenchmarkReap(b *testing.B) {
|
||||
func BenchmarkCheckTx(b *testing.B) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(b, cc)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
tx := make([]byte, 8)
|
||||
|
||||
@@ -39,8 +39,7 @@ func TestCacheRemove(t *testing.T) {
|
||||
func TestCacheAfterUpdate(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
|
||||
// reAddIndices & txsInCache can have elements > numTxsToCreate
|
||||
// also assumes max index is 255 for convenience
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -30,24 +29,19 @@ import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// A cleanupFunc cleans up any config / test files created for a particular
|
||||
// test.
|
||||
type cleanupFunc func()
|
||||
|
||||
func newMempoolWithApp(cc proxy.ClientCreator) (*CListMempool, cleanupFunc) {
|
||||
return newMempoolWithAppAndConfig(cc, cfg.ResetTestRoot("mempool_test"))
|
||||
func newMempoolWithApp(t testing.TB, cc proxy.ClientCreator) *CListMempool {
|
||||
return newMempoolWithAppAndConfig(t, cc, cfg.SetupTestConfiguration(t))
|
||||
}
|
||||
|
||||
func newMempoolWithAppAndConfig(cc proxy.ClientCreator, config *cfg.Config) (*CListMempool, cleanupFunc) {
|
||||
func newMempoolWithAppAndConfig(t testing.TB, cc proxy.ClientCreator, config *cfg.Config) *CListMempool {
|
||||
appConnMem, _ := cc.NewABCIClient()
|
||||
appConnMem.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "mempool"))
|
||||
err := appConnMem.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := appConnMem.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mempool := NewCListMempool(config.Mempool, appConnMem, 0)
|
||||
mempool.SetLogger(log.TestingLogger())
|
||||
return mempool, func() { os.RemoveAll(config.RootDir) }
|
||||
return mempool
|
||||
}
|
||||
|
||||
func ensureNoFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
|
||||
@@ -94,8 +88,7 @@ func checkTxs(t *testing.T, mempool Mempool, count int, peerID uint16) types.Txs
|
||||
func TestReapMaxBytesMaxGas(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
|
||||
// Ensure gas calculation behaves as expected
|
||||
checkTxs(t, mempool, 1, UnknownPeerID)
|
||||
@@ -143,8 +136,7 @@ func TestReapMaxBytesMaxGas(t *testing.T) {
|
||||
func TestMempoolFilters(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
emptyTxArr := []types.Tx{[]byte{}}
|
||||
|
||||
nopPreFilter := func(tx types.Tx) error { return nil }
|
||||
@@ -182,8 +174,7 @@ func TestMempoolFilters(t *testing.T) {
|
||||
func TestMempoolUpdate(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
|
||||
// 1. Adds valid txs to the cache
|
||||
{
|
||||
@@ -220,8 +211,7 @@ func TestMempoolUpdate(t *testing.T) {
|
||||
func TestTxsAvailable(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
mempool.EnableTxsAvailable()
|
||||
|
||||
timeoutMS := 500
|
||||
@@ -265,8 +255,7 @@ func TestSerialReap(t *testing.T) {
|
||||
app := counter.NewApplication(true)
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
|
||||
appConnCon, _ := cc.NewABCIClient()
|
||||
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
|
||||
@@ -387,8 +376,7 @@ func TestMempoolCloseWAL(t *testing.T) {
|
||||
wcfg.Mempool.RootDir = rootDir
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithAppAndConfig(cc, wcfg)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithAppAndConfig(t, cc, wcfg)
|
||||
mempool.height = 10
|
||||
err = mempool.InitWAL()
|
||||
require.NoError(t, err)
|
||||
@@ -424,11 +412,8 @@ func TestMempoolCloseWAL(t *testing.T) {
|
||||
func TestMempool_CheckTxChecksTxSize(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempl, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
|
||||
mempl := newMempoolWithApp(t, cc)
|
||||
maxTxSize := mempl.config.MaxTxBytes
|
||||
|
||||
testCases := []struct {
|
||||
len int
|
||||
err bool
|
||||
@@ -466,10 +451,9 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) {
|
||||
func TestMempoolTxsBytes(t *testing.T) {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
config := cfg.ResetTestRoot("mempool_test")
|
||||
config := cfg.SetupTestConfiguration(t)
|
||||
config.Mempool.MaxTxsBytes = 10
|
||||
mempool, cleanup := newMempoolWithAppAndConfig(cc, config)
|
||||
defer cleanup()
|
||||
mempool := newMempoolWithAppAndConfig(t, cc, config)
|
||||
|
||||
// 1. zero by default
|
||||
assert.EqualValues(t, 0, mempool.TxsBytes())
|
||||
@@ -503,10 +487,9 @@ func TestMempoolTxsBytes(t *testing.T) {
|
||||
// 6. zero after tx is rechecked and removed due to not being valid anymore
|
||||
app2 := counter.NewApplication(true)
|
||||
cc = proxy.NewLocalClientCreator(app2)
|
||||
mempool, cleanup = newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
|
||||
mempool = newMempoolWithApp(t, cc)
|
||||
txBytes := make([]byte, 8)
|
||||
|
||||
binary.BigEndian.PutUint64(txBytes, uint64(0))
|
||||
|
||||
err = mempool.CheckTx(txBytes, nil, TxInfo{})
|
||||
@@ -559,9 +542,8 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
config := cfg.ResetTestRoot("mempool_test")
|
||||
mempool, cleanup := newMempoolWithAppAndConfig(cc, config)
|
||||
defer cleanup()
|
||||
config := cfg.SetupTestConfiguration(t)
|
||||
mempool := newMempoolWithAppAndConfig(t, cc, config)
|
||||
|
||||
// generate small number of txs
|
||||
nTxs := 10
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestReactorBroadcastTxsMessage(t *testing.T) {
|
||||
// replace Connect2Switches (full mesh) with a func, which connects first
|
||||
// reactor to others and nothing else, this test should also pass with >2 reactors.
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -69,7 +69,7 @@ func TestReactorBroadcastTxsMessage(t *testing.T) {
|
||||
func TestReactorConcurrency(t *testing.T) {
|
||||
config := cfg.TestConfig()
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -130,7 +130,7 @@ func TestReactorConcurrency(t *testing.T) {
|
||||
func TestReactorNoBroadcastToSender(t *testing.T) {
|
||||
config := cfg.TestConfig()
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -154,7 +154,7 @@ func TestReactor_MaxBatchBytes(t *testing.T) {
|
||||
config.Mempool.MaxBatchBytes = 1024
|
||||
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -196,7 +196,7 @@ func TestBroadcastTxForPeerStopsWhenPeerStops(t *testing.T) {
|
||||
|
||||
config := cfg.TestConfig()
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -221,7 +221,7 @@ func TestBroadcastTxForPeerStopsWhenReactorStops(t *testing.T) {
|
||||
|
||||
config := cfg.TestConfig()
|
||||
const N = 2
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
|
||||
// stop reactors
|
||||
for _, r := range reactors {
|
||||
@@ -271,7 +271,7 @@ func TestMempoolIDsPanicsIfNodeRequestsOvermaxActiveIDs(t *testing.T) {
|
||||
func TestDontExhaustMaxActiveIDs(t *testing.T) {
|
||||
config := cfg.TestConfig()
|
||||
const N = 1
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
reactors := makeAndConnectReactors(t, config, N)
|
||||
defer func() {
|
||||
for _, r := range reactors {
|
||||
if err := r.Stop(); err != nil {
|
||||
@@ -302,15 +302,13 @@ func mempoolLogger() log.Logger {
|
||||
}
|
||||
|
||||
// connect N mempool reactors through N switches
|
||||
func makeAndConnectReactors(config *cfg.Config, n int) []*Reactor {
|
||||
func makeAndConnectReactors(t *testing.T, config *cfg.Config, n int) []*Reactor {
|
||||
reactors := make([]*Reactor, n)
|
||||
logger := mempoolLogger()
|
||||
for i := 0; i < n; i++ {
|
||||
app := kvstore.NewApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
mempool, cleanup := newMempoolWithApp(cc)
|
||||
defer cleanup()
|
||||
|
||||
mempool := newMempoolWithApp(t, cc)
|
||||
reactors[i] = NewReactor(config.Mempool, mempool) // so we dont start the consensus states
|
||||
reactors[i].SetLogger(logger.With("validator", i))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package state_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -49,8 +48,7 @@ func TestStoreLoadValidators(t *testing.T) {
|
||||
func BenchmarkLoadValidators(b *testing.B) {
|
||||
const valSetSize = 100
|
||||
|
||||
config := cfg.ResetTestRoot("state_")
|
||||
defer os.RemoveAll(config.RootDir)
|
||||
config := cfg.SetupTestConfiguration(b)
|
||||
dbType := dbm.BackendType(config.DBBackend)
|
||||
stateDB, err := dbm.NewDB("state", dbType, config.DBDir())
|
||||
require.NoError(b, err)
|
||||
|
||||
Reference in New Issue
Block a user