Skip to content

Commit

Permalink
fix(sims): OOM at sim-multi-seed-long run (cosmos#21503)
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe authored Sep 3, 2024
1 parent 50b2254 commit 62bf23a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sims-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
go-version: "1.23"
check-latest: true
- name: test-sim-multi-seed-long
env:
GOMEMLIMIT: 14GiB # reserve 2 GiB as buffer for GC to avoid OOM
run: |
make test-sim-multi-seed-long
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/simulations.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test-sim-custom-genesis-multi-seed:

test-sim-multi-seed-long:
@echo "Running long multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=1h -tags='sims' -run TestFullAppSimulation \
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=2h -tags='sims' -run TestFullAppSimulation \
-NumBlocks=150 -Period=50

test-sim-multi-seed-short:
Expand Down
12 changes: 8 additions & 4 deletions testutils/sims/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sims
import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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())
})
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/simulation/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetSimulatorFlags() {
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
flag.BoolVar(&FlagCommitValue, "Commit", true, "have the simulation commit")
flag.StringVar(&FlagDBBackendValue, "DBBackend", "goleveldb", "custom db backend type")
flag.StringVar(&FlagDBBackendValue, "DBBackend", "goleveldb", "custom db backend type: goleveldb, memdb")

// simulation flags
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
Expand Down

0 comments on commit 62bf23a

Please sign in to comment.