CosmWasm / wasmd

Basic cosmos-sdk app with web assembly smart contracts
Other
368 stars 400 forks source link

How to resolve `Could not lock exclusive.lock` #1930

Closed antstalepresh closed 3 months ago

antstalepresh commented 3 months ago

When writing test, test suite is used to simplify testing code. Here's the architecture of test.

func New() *App {
...
    homePath := cast.ToString(appOpts.Get(flags.FlagHome))
    wasmDir := filepath.Join(homePath, "wasm")
    wasmer, err := wasmvm.NewVM(
        filepath.Join(wasmDir, "wasm"),
        availableCapabilities,
        32, // wasmkeeper.contractMemoryLimit,
        wasmConfig.ContractDebugMode,
        wasmConfig.MemoryCacheSize,
    )
    if err != nil {
        panic(err)
    }
...
}

func Setup()  *App {
...
    app := New(
        log.NewNopLogger(),
        db,
        nil,
        true,
        appOptions,
        wasmOpts,
    )
...
}

type KeeperTestSuite struct {
    suite.Suite

    ctx sdk.Context

    app *app.App
}

func (suite *KeeperTestSuite) SetupTest() {
    suite.app = app.Setup(suite.T(), false)
    suite.ctx = suite.app.BaseApp.NewContext(false)
}

func (suite *KeeperTestSuite) Test1() {
...
}

func (suite *KeeperTestSuite) Test2() {
...
}

When Test1 and Test2 are run individually, it works fine, but when they are run both, it is returning following issue.

test panicked: Could not lock exclusive.lock. Is a different VM running in the same directory already?
            goroutine 315 [running]:

Would be nice to get recommendation for the best way to fix the issue in test suite.

webmaster128 commented 3 months ago

This is a newly added safety check implemented in wasmvm 2. The idea is that no two wasmvm.VM instances should run on the same directory at the same time. When you write tests that run in parallel, you need to use a different directory for each test. So more or less create a temp dir here for each test:

wasmDir := filepath.Join(homePath, "wasm")
antstalepresh commented 3 months ago

Thanks for your input, closing the issue.