From fbfb6e59c9c5e8dbc4157ef49d0248f03dcf10e1 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:27:08 +0000 Subject: [PATCH] fix(sims): OOM at sim-multi-seed-long run (backport #21503) (#21517) Co-authored-by: Alexander Peters Co-authored-by: Julien Robert --- .github/workflows/sims-nightly.yml | 2 ++ scripts/build/simulations.mk | 2 +- testutils/sims/runner.go | 14 +++++++++----- x/simulation/client/cli/flags.go | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sims-nightly.yml b/.github/workflows/sims-nightly.yml index 35f6232bdf25..0473bcad5268 100644 --- a/.github/workflows/sims-nightly.yml +++ b/.github/workflows/sims-nightly.yml @@ -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 diff --git a/scripts/build/simulations.mk b/scripts/build/simulations.mk index ea7510db4cb8..4020d468a920 100644 --- a/scripts/build/simulations.mk +++ b/scripts/build/simulations.mk @@ -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: diff --git a/testutils/sims/runner.go b/testutils/sims/runner.go index 34acc544bdc0..2af22f8c5ad8 100644 --- a/testutils/sims/runner.go +++ b/testutils/sims/runner.go @@ -3,6 +3,7 @@ package sims import ( "fmt" "io" + "os" "path/filepath" "testing" @@ -49,6 +50,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. @@ -113,7 +115,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( @@ -123,7 +124,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, @@ -133,12 +134,13 @@ func RunWithSeeds[T SimulationApp]( require.NoError(t, err) err = simtestutil.CheckExportSimulation(app, tCfg, simParams) require.NoError(t, err) - if tCfg.Commit { - simtestutil.PrintStats(testInstance.DB) + if tCfg.Commit && tCfg.DBBackend == "goleveldb" { + simtestutil.PrintStats(testInstance.DB.(*dbm.GoLevelDB)) } for _, step := range postRunActions { step(t, testInstance) } + require.NoError(t, app.Close()) }) } } @@ -172,6 +174,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 { @@ -184,7 +188,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 diff --git a/x/simulation/client/cli/flags.go b/x/simulation/client/cli/flags.go index 409e2aabf80a..311ce7017d85 100644 --- a/x/simulation/client/cli/flags.go +++ b/x/simulation/client/cli/flags.go @@ -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")