gojs/test: resolve race under scheduleTimeoutEvent (#1063)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -16,14 +16,20 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
gojs "github.com/tetratelabs/wazero/imports/go"
|
||||
"github.com/tetratelabs/wazero/internal/fstest"
|
||||
internalgojs "github.com/tetratelabs/wazero/internal/gojs"
|
||||
"github.com/tetratelabs/wazero/internal/gojs/run"
|
||||
"github.com/tetratelabs/wazero/internal/wasm"
|
||||
binaryformat "github.com/tetratelabs/wazero/internal/wasm/binary"
|
||||
)
|
||||
|
||||
func compileAndRun(ctx context.Context, arg string, config wazero.ModuleConfig) (stdout, stderr string, err error) {
|
||||
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig().WithCompilationCache(cache))
|
||||
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig().
|
||||
// https://github.com/tetratelabs/wazero/issues/992
|
||||
WithMemoryCapacityFromMax(true).
|
||||
WithCompilationCache(cache))
|
||||
return compileAndRunWithRuntime(ctx, rt, arg, config) // use global runtime
|
||||
}
|
||||
|
||||
@@ -96,6 +102,20 @@ func TestMain(m *testing.M) {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// In order to avoid race condition on scheduleTimeoutEvent, we need to set the memory max
|
||||
// and WithMemoryCapacityFromMax(true) above.
|
||||
// https://github.com/tetratelabs/wazero/issues/992
|
||||
//
|
||||
// TODO: Maybe add WithMemoryMax API?
|
||||
parsed, err := binaryformat.DecodeModule(testBin, api.CoreFeaturesV2, wasm.MemoryLimitPages, false, false, false)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
// Set max to a high value, e.g. so that Test_stdio_large can pass
|
||||
parsed.MemorySection.Max = 1024 // 64MB
|
||||
parsed.MemorySection.IsMaxEncoded = true
|
||||
testBin = binaryformat.EncodeModule(parsed)
|
||||
|
||||
// Seed wazero's compilation cache to see any error up-front and to prevent
|
||||
// one test from a cache-miss performance penalty.
|
||||
r := wazero.NewRuntimeWithConfig(testCtx, wazero.NewRuntimeConfig().WithCompilationCache(cache))
|
||||
|
||||
@@ -766,7 +766,7 @@ type Import struct {
|
||||
// Memory describes the limits of pages (64KB) in a memory.
|
||||
type Memory struct {
|
||||
Min, Cap, Max uint32
|
||||
// IsMaxEncoded true if the Max is encoded in the original source (binary or text).
|
||||
// IsMaxEncoded true if the Max is encoded in the original binary.
|
||||
IsMaxEncoded bool
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user