Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test memory usage of the wazero engine #1609

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions internal/integration_test/engine/memleak_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package adhoc

import (
"context"
"log"
"runtime"
"testing"
"time"

"github.com/tetratelabs/wazero"
)

func TestMemoryLeak(t *testing.T) {
if testing.Short() {
t.Skip("skipping memory leak test in short mode.")
}

duration := 5 * time.Second
t.Logf("running memory leak test for %s", duration)

ctx, cancel := context.WithTimeout(context.Background(), duration)
defer cancel()

for ctx.Err() == nil {
if err := testMemoryLeakInstantiateRuntimeAndModule(); err != nil {
log.Panicln(err)
}
}

var stats runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&stats)

if stats.Alloc > (100 * 1024 * 1024) {
t.Errorf("wazero used more than 100 MiB after running the test for %s (alloc=%d)", duration, stats.Alloc)
}
}

func testMemoryLeakInstantiateRuntimeAndModule() error {
ctx := context.Background()

runtime := wazero.NewRuntime(ctx)
defer runtime.Close(ctx)

mod, err := runtime.InstantiateWithConfig(ctx, memoryWasm,
wazero.NewModuleConfig().WithStartFunctions())
if err != nil {
return err
}
return mod.Close(ctx)
}