fix(sims): OOM at sim-multi-seed-long run (#21503)

This commit is contained in:
Alexander Peters
2024-09-03 13:41:22 +00:00
committed by GitHub
parent 50b2254249
commit 62bf23a5ae
4 changed files with 12 additions and 6 deletions
+8 -4
View File
@@ -3,6 +3,7 @@ package sims
import (
"fmt"
"io"
"os"
"path/filepath"
"testing"
@@ -50,6 +51,7 @@ type SimulationApp interface {
SetNotSigverifyTx()
GetBaseApp() *baseapp.BaseApp
TxConfig() client.TxConfig
Close() error
}
// Run is a helper function that runs a simulation test with the given parameters.
@@ -114,7 +116,6 @@ func RunWithSeeds[T SimulationApp](
runLogger = log.NewTestLoggerInfo(t)
}
runLogger = runLogger.With("seed", tCfg.Seed)
app := testInstance.App
stateFactory := setupStateFactory(app)
simParams, err := simulation.SimulateFromSeedX(
@@ -124,7 +125,7 @@ func RunWithSeeds[T SimulationApp](
app.GetBaseApp(),
stateFactory.AppStateFn,
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simtestutil.SimulationOperations(app, stateFactory.Codec, tCfg, testInstance.App.TxConfig()),
simtestutil.SimulationOperations(app, stateFactory.Codec, tCfg, app.TxConfig()),
stateFactory.BlockedAddr,
tCfg,
stateFactory.Codec,
@@ -134,12 +135,13 @@ func RunWithSeeds[T SimulationApp](
require.NoError(t, err)
err = simtestutil.CheckExportSimulation(app, tCfg, simParams)
require.NoError(t, err)
if tCfg.Commit {
if tCfg.Commit && tCfg.DBBackend == "goleveldb" {
simtestutil.PrintStats(testInstance.DB.(*dbm.GoLevelDB))
}
for _, step := range postRunActions {
step(t, testInstance)
}
require.NoError(t, app.Close())
})
}
}
@@ -173,6 +175,8 @@ func NewSimulationAppInstance[T SimulationApp](
) TestInstance[T] {
t.Helper()
workDir := t.TempDir()
require.NoError(t, os.Mkdir(filepath.Join(workDir, "data"), 0o755))
dbDir := filepath.Join(workDir, "leveldb-app-sim")
var logger log.Logger
if cli.FlagVerboseValue {
@@ -185,7 +189,7 @@ func NewSimulationAppInstance[T SimulationApp](
db, err := dbm.NewDB("Simulation", dbm.BackendType(tCfg.DBBackend), dbDir)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, db.Close())
_ = db.Close() // ensure db is closed
})
appOptions := make(simtestutil.AppOptionsMap)
appOptions[flags.FlagHome] = workDir